集合中的Cloud Firestore列表文档ID

时间:2019-09-11 20:12:39

标签: javascript firebase google-cloud-firestore

为了减少对Cloud Firestore数据库的读取量,我想在实际使用get()之前获取集合中所有文档ID的列表。

Understand Cloud Firestore billing页上显示

  

对于文档读取以外的查询(例如要求收集ID的列表),您需要为读取的一个文档付费

this question可以很明显地看出,collection.get()会向您收取馆藏中文件数量的费用。因此,我想知道是否还有一种仅获取文档ID的方法。

这是我目前正在使用的

firestore.collection('path').get()
.then(querySnapshot => {
  querySnapshot.forEach(doc => {
    if (!alreadyUsed(doc.id)) {
      var data = doc.data()
      // do something with data
    }
  })
})

我想要这样的东西

var collection = firestore.collection('path')
collection.getIDs()
.then(ids => {
  ids.forEach(id => {
    if (!alreadyUsed(id)) {
      collection.doc(id).get()
      .then(snapshot => {
        var data = snapshot.data()
        // do something with data
      })
    }
  })
})

0 个答案:

没有答案
相关问题