Firestore查询仅包含集合的文档 [英] Firestore query documents with only collections inside

查看:98
本文介绍了Firestore查询仅包含集合的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个firestore集合,里面有一些文档。文档仅包含集合而不包含任何字段。因此,当我尝试获取根集合中的所有文档时,我将快照大小设置为零。有没有办法获得没有字段但内部有一些集合的文件?

I have a firestore collection which has some documents inside it. The documents contains only collections not any fields. So when I try to get all documents inside the root collection i got the snapshot size as zero. Is there any way to get the documents which has no fields but has some collection inside it?

我的火库结构是

您还可以看到文档的ID以斜体显示

You can also see that the id of documents is shown in italics

检索数据的代码

  db.collection("transactions").get()
    .then(snapshot => { 
      console.log(snapshot.size); returns zero
    })


推荐答案

let date = '2017-12-20' //date to be set in doc

db.collection("transactions").doc(date).set({
  //set an empty object for each doc in transaction before your method 
  //of setting data 
  //This will create a field for each doc in transaction
})
.then(()=>{
  //your method of setting data here.
})
//Your query method here.
//Now you will be able to query the docs in collection - transaction.

这篇关于Firestore查询仅包含集合的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆