0

I have array of user IDs in my firestore collection. I want to make query in Node js to get every document that does not include some specific id

db.collection("freeMusic").where("userIds", "array-contains", "ABB56WnLNWdbWNTyItrRiQyfgCU2")
      .get()

This is how I can get in which document there is specific user ID in array userIds but how can I do in reverse?

How to query every document that doesn't include specific value in array?

NOTE: This array of userIds can have big length even more than 100

HardRock
  • 809
  • 2
  • 12
  • 37
  • How about `where("userIds", "not-in",[ "ABB56WnLNWdbWNTyItrRiQyfgCU2"])?` – Ritesh Kumar Gupta May 20 '21 at 11:08
  • Is it possible to combine this with multiple where condtions in one query? – HardRock May 20 '21 at 11:12
  • You can try this: `var ref= db.collection("freeMusic"); ref.where("userIds", "not-in",[ "ABB56WnLNWdbWNTyItrRiQyfgCU2"]); ref=ref.where("userIds", "not-in",[ "xkk"]); ref=ref.where ... ; ref.get();` – Ritesh Kumar Gupta May 20 '21 at 11:21
  • Even with your answer not-in I'm getting only one which contains that userID where query `.where("answeredUids", "not-in", ["ZBZ53WnLNWdbWNTyIekRiQyhoCK2"]);` and result `"answeredUids": [ "ZBZ53WnLNWdbWNTyIekRiQyhoCK2" ]` – HardRock May 20 '21 at 11:28
  • I linked two questions to yours. In one Doug explains why this sort of query isn't possible on Firestore (it always goes back to it being able to meet its performance guarantee). In the other Jay explains a data model that might work for your use-case too. – Frank van Puffelen May 20 '21 at 14:59

0 Answers0