扫码关注官方订阅号
我想知道是否可以在 Firestore 数据库的一次往返(网络调用)中通过 ID 列表获取多个文档。
实际上,您会像这样使用 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()))) }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
实际上,您会像这样使用 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()))) }