Ruchika Suryawanshi
Ruchika Suryawanshi

Reputation: 11

How to use OR operator in flutter firebase?

My firestore field can contain either the value of gender as ‘MEN’, ‘WOMEN’ or ‘UNISEX’. So I want to get the documents where the field is either MEN or WOMEN.

QuerySnapshot snap = await myReference.where('gender',isEqualTo:'MEN').limit(6).get();

How can I extend this query for it?

Upvotes: 0

Views: 138

Answers (2)

Abdulrahman Osama
Abdulrahman Osama

Reputation: 271

As Dharmaraj mentioned, Cloud Firestore is now supported IN operator. you can use WhereIN operator that support up to 10 comparison values. the code could be :

QuerySnapshot snap = await myReference.where('gender',whereIn:['MEN','WOMEN','UNISEX']).limit(6).get();

Note: this soultion has some other limitations as written in the documentation

Upvotes: 0

Dharmaraj
Dharmaraj

Reputation: 50840

You can use whereIn operator to get documents for required genders.

QuerySnapshot snap = await myReference.where('gender', whereIn:['MEN', 'WOMEN']).limit(6).get();

This query will fetch documents where the field gender is equal to either of the values mentioned in that array passed as value of whereIn

Upvotes: 1

Related Questions