为了减少对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
})
}
})
})