I have a collection the docs of which have an array property members
which contains user IDs. I need to find the docs the members of which are a pair of user IDs, eg.:
From the docs for compound queries I can see how to make an OR
, but I need an AND
, because I need the docs that contain both user IDs (which actually is what makes a doc unique). The docs say that
you can include at most one array-contains or array-contains-any clause in a compound query
so, the following code doesn't work (I tested and it actually returns an error):
const conversation = await firebaseDb.collection(collectionName)
.where('members', 'array-contains', userId)
.where('members', 'array-contains', otherUserId)
.get();
I tried this as well:
const conversation = await firebaseDb.collection(collectionName)
.where('members', 'array-contains', [userId, otherUserId])
.get();
but it returns nothing.
Is it actually possible to perform a logical AND
on array values in a Firestore doc?