tailor
tailor

Reputation: 443

How do I make query with string list of firebase realtime databse

I have a predefined List<String>. Now in my app I retrieved data from Firebase database. Generally I used:

DatabaseReference reference = FirebaseDatabase.getInstance().getReference();

    Query query = reference.child("Users").orderByChild("id").equalTo("string");

But for more stuff I want to filter data from my List<String>. So is this possible like below query?

Query query = reference.child("Users").orderByChild("id").equalTo(***String_exists_in_predefined_list***);

Upvotes: 4

Views: 1282

Answers (2)

SABANTO
SABANTO

Reputation: 1506

Get the string from your predefined list in oncreate. Call the method with your query and carry over the string and use it there.

Inside oncreate

String fromlist = [retrieve here];
queryData(fromlist);

Upvotes: 0

Alex Mamo
Alex Mamo

Reputation: 138824

So is this possible like below query ??

No, it's not possible. You cannot pass a list of strings as the second argument to the equalTo() method because there is no such a method that accepts that. You need to iterate over the list and create a query for each one of those elements and merge the result client side.

Edit:

You need to loop through the list and create a query for each element:

for(String element : list) {
    Query query = reference.child("Users").orderByChild("id").equalTo(element);
}

Upvotes: 1

Related Questions