Google Firestore - how to get document by multiple

2018-12-31 10:21发布

I am wondering if it's possible to get multiple documents by list of ids in one round trip (network call) to the Firestore.

7条回答
梦寄多情
2楼-- · 2018-12-31 11:03

In practise you would use firestore.getAll like this

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()))
}

or with promise syntax

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())))
}
查看更多
登录 后发表回答