Home > Software design >  Firestore query by document Id and another property
Firestore query by document Id and another property

Time:10-05

I want to know if it is possible to do the following query, using the Id of the document and another property.

await firestore
  .collection('organizations')
  .doc(props.organizationId)
  .where('members', 'array-contains', userId)

CodePudding user response:

You can use FieldPath.documentId() to filter on the document ID in a query. So:

await firestore
  .collection('organizations')
  .where(firebase.firestore.FieldPath.documentId(), '==', props.organizationId)
  .where('members', 'array-contains', userId)
  • Related