-1

Is there any way to query a document so that any field is equal to some value?

eg:

collection of documents named chats. Each document has two fields - user1 and user2. Can I get all the documents where user1 or user2 is 2?

where('field', 'in', ['value1', 'value2']) won't work for this because that can only check one field against multiple values. right?

Basith P
  • 9
  • 3

1 Answers1

1

Firestore does not support OR queries: Perform simple and compound queries in Cloud Firestore

However you can fetch all documents in chats with user1 === 2 and a second fetch with all documents with user2 === 2 and concat the results

let combinedChatArray = chatOfUser1Array.concat(chatOfUser2Array);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459