如果我们想通过其 ID查询一个文档,我们可以这样做:
firebase
.firestore()
.collection("Your collection")
.doc("documentId")
.get()
.then((docRef) => { console.log(docRef.data()) })
.catch((error) => { })
如何在给定 ID 列表的情况下查询一组文档,例如:
var list_of_ids = ["documentId1", "documentId2", "documentId3"]
firebase
.firestore()
.collection("Your collection")
.doc(list_of_ids)
.get()
.then((docRef) => { console.log(docRef.data()) })
.catch((error) => { })
谢谢达玛拉吉。
var list_of_ids = ["documentId1", "documentId2", "documentId3"]
firebase
.firestore()
.collection("Your collection")
.where('__name__', 'in', list_of_ids)
.get()
.then((docRef) => { console.log(docRef.data()) })
.catch((error) => { })
如果数组少于或等于 10 个 ID,则可以使用in
运算符:
.where('__name__', 'in', list_of_ids)
如果数组包含 10 个以上的项目,则您必须为每个文档单独请求(或批量生成 10 个)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句