subrata sharma
subrata sharma

Reputation: 344

Can I use WhereEqualTo two time in the same field?

I want to sort data in BUCKET_1_KEY field by two data, but it's not working in my case. Is it possible?

db.collection(XPERT_MASTER_KEY)
                .document(xpertId)
                .collection(RESPONSES_KEY)
                .whereEqualTo(BUCKET_1_KEY, "exp")
                .whereEqualTo(BUCKET_1_KEY, "option")

Upvotes: 0

Views: 629

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317427

Conditions in Firestore queries are logically AND'd with each other. Therefore, it doesn't make sense to have two equals conditions in a single query on the same field. A field value cannot possibly be equal to two different strings at the same time.

If you are trying to implement a logical OR query, trying to get all documents where BUCKET_1_KEY is equal to "exp" OR BUCKET_1_KEY is equals to "options", you should be using a IN query instead. Please read the documentation about IN queries. If you are trying to perform a logical OR with an IN query, it would look like this:

db.collection(XPERT_MASTER_KEY)
                .document(xpertId)
                .collection(RESPONSES_KEY)
                .whereIn(BUCKET_1_KEY, Arrays.asList("exp", "option"))

Upvotes: 4

Related Questions