我想知道是否有可能在Firestore数据库的一次往返(网络调用)中通过I列表获取多个文档。
发布于 2019-11-09 22:46:38
他们刚刚宣布了这项功能,https://firebase.googleblog.com/2019/11/cloud-firestore-now-supports-in-queries.html。
现在您可以使用这样的查询,但要记住输入大小不能大于10。
userCollection.where('uid', 'in', ["1231","222","2131"])
发布于 2018-11-28 06:07:19
在实践中,您可以像这样使用firestore.getAll
async getUsers({userIds}) {
const refs = userIds.map(id => this.firestore.doc(`users/${id}`))
const users = await this.firestore.getAll(...refs)
console.log(users.map(doc => doc.data()))
}
或者使用promise语法
getUsers({userIds}) {
const refs = userIds.map(id => this.firestore.doc(`users/${id}`))
this.firestore.getAll(...refs).then(users => console.log(users.map(doc => doc.data())))
}
发布于 2018-05-17 23:14:00
您可以使用如下函数:
function getById (path, ids) {
return firestore.getAll(
[].concat(ids).map(id => firestore.doc(`${path}/${id}`))
)
}
可以使用单个ID进行调用:
getById('collection', 'some_id')
或ID数组:
getById('collection', ['some_id', 'some_other_id'])
https://stackoverflow.com/questions/46721517
复制相似问题