--- Users (Collection)
|
--- p0A1fXH4l2TpvGE2lo0x
|
--- List (HashMap)
|
--- ID (String) (Value: UQx4CWRgnVLOdKEY3AKJ)
--- NAME (String) (Value: ...)
In Firestore, how can I find the documents that have a list ID equal to UQx4CWRgnVLOdKEY3AKJ
? Before deleting the list, I need to remove it from the users who have used it. How can I determine which documents are using this list ID so I can delete them?
2
Answers
It looks like your
List (HashMap)
may have multiple child objects, and you want to search across all of those for a specific ID value.There is no way to search across all objects in a map field in Firestore. If you want to search across all ID values, add an additional array field with just this values, e.g.
With that field in place, you can then use the
array-contains
operator to query for matching documents.If I understand correctly, the
List
field inside the user document is aMap
which contains only String values. So if your database schema looks exactly like this:To get all users where the
ID
field within theList
holds the value ofUQx4CWRgnVLOdKEY3AKJ
, a query like this will do the trick: