I have 2 collections "photos" and "users" and each document in "users" has one or more photo IDs with an array.
photos > 5528c46b > name: "Photo1" a1e820eb > name: "Photo2" 32d410a7 > name: "Photo3"
users > acd02b1d > name: "John", photos: ["5528c46b"] 67f60ad3 > name: "Tom", photos: ["5528c46b", "32d410a7"] 7332ec75 > name: "Sara", photos: ["a1e820eb"] 9f4edcc1 > name: "Anna", photos: ["32d410a7"]
I want to get all users who have one or more specific photo IDs.
Are there any ways to do that?
See Henry's answer, as we've no made Array Contains queries available.
Unfortunately not yet, although it's on our roadmap.
In the meantime, you'll need to use a map instead, in the form of:
photos: { id1: true id2: true }
Now you can find all users with id1 by filtering by photos.id1 == true
.
Read more about querying such sets in the Firebase documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With