[英]get collection of documents with firestore
I was following this example:我在关注这个例子:
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);
});
I want to return an array of people within the city of SF.我想返回旧金山市内的一系列人。
According to https://firebase.google.com/docs/database/web/structure-data根据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.
当您在数据库中的某个位置获取数据时,您还会检索其所有子节点。
but I can´t find the right to return the collection within a doc (without making a new query)但我找不到在文档中返回集合的权利(不进行新查询)
In Firestore when you retrieve the data, you retrieve all the fields inside a document.在 Firestore 中,当您检索数据时,您将检索文档中的所有字段。 If you want to retrieve data from another document or from subcollection then you need to do a different query.
如果要从另一个文档或子集合中检索数据,则需要执行不同的查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.