Google cloud firestore Cloud Firestore如何查找包含特定文档ID的子集合的所有文档?
我正试图实现一种在Firestore中保持一致性的方法,但我需要一种找到所有存在重复数据的位置的方法。firestore中是否有方法查找其子集合包含具有特定文档ID的文档的所有文档?例如,对于以下结构Google cloud firestore Cloud Firestore如何查找包含特定文档ID的子集合的所有文档?,google-cloud-firestore,Google Cloud Firestore,我正试图实现一种在Firestore中保持一致性的方法,但我需要一种找到所有存在重复数据的位置的方法。firestore中是否有方法查找其子集合包含具有特定文档ID的文档的所有文档?例如,对于以下结构 Users(collections){ 1234(document){ Name: Friends(collection){ 5678(document) { Name: }
Users(collections){
1234(document){
Name:
Friends(collection){
5678(document) {
Name:
}
9012(document) {
Name:
}
}
5678(document){
Name:
}
}
我将使用什么查询来查找其好友列表包含文档ID为5678的文档的所有用户ID?例如,当用户5678决定更改其姓名时?不完全正确。早在5月份,就引入了集合组查询,它允许您搜索具有相同名称的所有集合,但该限制不适用于您的用例,因为您的用户存储在
users
中,而他们的朋友存储在friends
中
如果朋友被重命名以匹配用户,并且id
也存储在文档中,则可以使用这种类型的查询:
let friends = db.collectionGroup('users').where('id', '==', id);
friends.get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, ' => ', doc.data());
});
});