我正在关注以下示例:
var docRef = db.collection("cities").doc("SF");
docRef.get().then(function(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
// this is not working
const people = doc.collection("people");
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
我想返回旧金山市内的一群人。
根据https://firebase.google.com/docs/database/web/structure-data
当您在数据库中的某个位置获取数据时,您还将检索其所有子节点。
但我找不到在文档中返回集合的权利(不进行新查询)
最佳答案
在Firestore中,当您检索数据时,将检索文档中的所有字段。如果要从另一个文档或子集合中检索数据,则需要执行其他查询。