I need to create a compound query that retrieves all the document with a specific value in a map in an array. The useful part of my database looks like the following:
appointments(collection)
doc1(document)
people(array)
person1(map)
userId(field)
person2(map)
userId(field)
I need to get all the documents(like doc1) that have people with the specific userId, which is in a constant. I have a global idea of what needs to happen, but I don't really understand the query. I currently have the following:
const snapshot = db.collection('appointments').where('people.userId', 'array_contains', userId).get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
db.collection('appointments').doc(doc.id).update({
//Change the data I need to change
},{merge:true});
});
});
I cannot figure out how to construct this where clause. Can anyone help me with this? Thanks in advance!