Reputation: 683
Hi so I have this exact db schema where there are documents with a field called "status", this field has different values, it can be "pending", "sent" and etc..
I have a FirebaseUI Recycler and I want to load all documents that contain that 2 values. So far I've tried this code:
Query query = fStore.collection("friendRequests").document(currentUID)
.collection("userFriendRequest")
.whereEqualTo("status", "pending") //1 condition
.whereEqualTo("status", "sent"); //2 condition
But I'm having trouble with that since it doesn't return nothing , I've tried with arrays but I couldn't make it work aswell.
Question: Any idea where I'm missing?
Upvotes: 1
Views: 1066
Reputation: 80914
This query is an AND condition, and it wont work since a field in one document cannot have two values, you can do the following:
Query query = fStore.collection("friendRequests").document(currentUID)
.collection("userFriendRequest")
whereIn("status", Arrays.asList("pending", "sent");
Use the in operator to combine up to 10 equality (==) clauses on the same field with a logical OR. An in query returns documents where the given field matches any of the comparison values
https://firebase.google.com/docs/firestore/query-data/queries#in_and_array-contains-any
Upvotes: 4