• 10

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am trying to query nodes from Firebase realtime database to my firebase recycler adapter where "userId" child value is found in a String ArrayList.

So I have a node called "Follows" where every users follows inside the app are stored. It looks like this. Then I have node called "Posts" where every post by any user is stored. Every indivitual post have multiple childs containing info about the post and one of them is child called "userId". Looking like this.

I have retrieved each follows user id like this:

final ArrayList<String> usersFollows = new ArrayList<>();
                    DatabaseReference usersFollowsRef = FirebaseDatabase.getInstance().getReference().

                    usersFollowsRef.addListenerForSingleValueEvent(new ValueEventListener() {
                        public void onDataChange(DataSnapshot dataSnapshot)
                                for(DataSnapshot snapshot : dataSnapshot.getChildren())
                                    String followsKey = snapshot.getKey();

                        public void onCancelled(DatabaseError databaseError) {


Now I would have to make a query which retrieves every post that has "userId" value found in this "usersFollows" ArrayList but I don't really know how to achieve my goal. For example I cant write Query query = postsReference.orderByChild("userId").equalTo(usersFollows); because you cant pass an array inside equalTo() statement.

Am I on the right path or is there a more convinient way of doing this?

Unfortunately, firebase doesn't allow multiple equalTo(). I suggest you to review your db in that way: Posts -> Date -> UserId -> PostId and adding a .read rules that check if the UserId in Follow list is true:

Posts: {
  "$date" :{
     "$userId": {
                ".read": "root.child(follows).child(auth.uid).child($userId).val() === true"

In this way you can obtain the post by date and automatically reduce the visibility scope.


You can maintain your actual schema adding this rule:

 Posts: {
        ".read": "root.child(follows).child(auth.uid).child(data.child(userId)).val() === true"
  • 1
Reply Report
      • 2
    • So there is no way I can for example loop through all of the posts and create an array from the post ids and query somehow by them? I have been developing this app for quite a while now and if I make changes to my db structure I would have to modify a lot of code.
      • 1
    • Sorry, I'm not so familiar with rules in firebase realtime database. What kind of query would I have to do with this rule?
      • 1
    • You can run the query that gets all the posts: the rules change the scope of visibility directly from the server and you don't have to do any filtering by the app. I suggest you to study them here and add them in your application.