Firebase 数组firestore中带映射的复合查询

Firebase 数组firestore中带映射的复合查询,firebase,google-cloud-firestore,google-cloud-functions,Firebase,Google Cloud Firestore,Google Cloud Functions,我需要创建一个复合查询来检索数组中映射中具有特定值的所有文档。我的数据库的有用部分如下所示: appointments(collection) doc1(document) people(array) person1(map) userId(field) person2(map) userId(field) const snapshot = db.collec

我需要创建一个复合查询来检索数组中映射中具有特定值的所有文档。我的数据库的有用部分如下所示:

appointments(collection)
    doc1(document)
        people(array)
            person1(map)
                userId(field)
            person2(map)
                userId(field)
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});
           });
});
我需要获取所有文档(如doc1),其中包含具有特定用户ID的人员,该用户ID是常量。我对需要发生什么有一个全局性的想法,但我并不真正理解这个问题。我目前有以下情况:

appointments(collection)
    doc1(document)
        people(array)
            person1(map)
                userId(field)
            person2(map)
                userId(field)
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});
           });
});
我不知道如何构造where子句。有人能帮我吗?
提前谢谢

在Firestore中无法查询数组中的嵌套映射值。您必须将这些数据转换为可以查询的数据,或者将足够多的数据复制到另一个字段中以使之成为可能


您可以做的一件事是创建一个只包含用户ID字符串的新字段,并在该数组上使用数组contains查询。

那么这会是什么样子,因为如果我有一个单独的带有用户ID的数组,我就不知道要更新哪些数据。我在这里遗漏了什么吗?如果有什么变化,您必须编写代码来更新所有重复的数据。这在数据重复的nosql类型数据库中很常见。因此,如果我创建一个包含所有用户ID的数组,我可以找到需要更改内容的所有文档,然后在数组中循环并测试是否有正确的数据(通过使用change.before.data()),然后更改数据,这样行吗?