我正在使用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的Promise,其中不仅包含文档,还包含更多内容。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不会强制执行或记录您的架构;这是作为开发人员的[[您的工作。
特雷西大厅