In Cloud Firestore I am needing to find matches in an array that contains maps using the array-contains
query.
I can very easily match direct strings, numbers etc however it always fails when the values of the array is a map. The documentation doesn't allude to is this is possible or not.
Here is an example of some data
{
data:
[
item_1: {...},
item_2: {...}
]
}
and here is an example of the query
db.collection("list")
.where("data", "array-contains", "item_1")
.get()
.then(collectionRef => {
//do something with collection
})
I am expecting the array-contains to match the top value (item_x) of the map, at the moment it doesn't match this. I assume this is because it wants to match the entire content of the map as the "value" of the array item.
Any help would be appreciated. I might have to re-think my data structure if this is not possible. For context I am using this in a cloud function to update items (they are a reference to a doc) in an array when their original doc is updated.
array-contains queries only match the entire item in an array. If that item is an object, the query must provide the entire, exact object to match for equality in the array.
What you're doing right now isn't supported. You will have to provide some other field in the document to search against, possibly duplicating data in that document, which is common for NoSQL type databases.
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