繁体   English   中英

如何从firestore获取集合数据

[英]How to get Collection Data from firestore

我正在使用火店

我有健康名收藏

collection health
doc customername
collection customerinfo  // multiple
doc customerwardinfo

代码:

firebase.firestore()
        .collection("health")
        .doc('customername')
        .get()
        .then((data)=>{            
            console.log("customer data",data);
        })

我正在使用上面的代码但没有获取数据。 我想为每个子集合使用。 但我无法实现它。 我将如何获得所有数据。 假设一个集合有 10 个文档。 然后对每个文档使用 foreach 并从每个文档中获取数据。

.doc().get() 不返回文档的承诺; 它返回一个 DocumentSnapshot 的承诺,其中包含的不仅仅是文档。 https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentSnapshot

如您所见,DocumentSnapshot 具有属性“exists”、“metadata”、“id”和“ref”,以及方法“data()”[返回带有文档字段的对象 - 数据]、“get()” [它可以从文档中返回指定的字段],以及“isEqual()”,它可以比较 DocumentSnapshots。

在 .doc().get().get() 上 - 虽然最终结果只是请求的字段,但整个文档都是从数据库/商店中获取的。

正如 Frank van Puffelen 所提到的,无法检索子集合列表 - Firestore 不会强制执行或记录您的架构; 这是作为开发人员的工作。

特蕾西·霍尔

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM