javascript - 使用 firestore 获取文档集合

标签 javascript firebase google-cloud-firestore

我正在遵循这个例子:

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/

相关文章:

javascript - 在 JavaScript 和 PHP 之间传递语言字符

firebase - 在没有 AppDelegate 和 SceneDelegate 的新 SwiftUI 应用程序生命周期中,我的 iOS 应用程序在哪里配置 Firebase?

javascript - 使用电子邮件和密码错误验证用户身份

firebase - 有没有办法向正在运行的 Firebase 模拟器添加/修改功能?

javascript - 使用 JQuery 评分星级并将数据提交给分析

javascript - 当焦点位于 TextArea 上时按 Enter 键提交表单?

javascript:在创建的div中的h1中显示提示文本

android - Firebase 身份验证 - 发生网络错误(例如超时、连接中断或主机无法访问)

arrays - 嵌套的循环无法在Flutter中正常工作

javascript - 如何使用 firestore 执行动态 where 查询并添加索引