我正在遵循这个例子:
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);
});
我想返回 SF 市内的一群人。
根据https://firebase.google.com/docs/database/web/structure-data
when you fetch data at a location in your database, you also retrieve all of its child nodes.
但我找不到在文档中返回集合的权利(无需进行新查询)
最佳答案
在 Firestore 中检索数据时,您会检索文档内的所有字段。如果您想从另一个文档或子集合中检索数据,那么您需要执行不同的查询。
关于javascript - 使用 firestore 获取文档集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61291402/