Firebase,通过文档 ID 列表查询文档列表

叮当声

如果我们想通过其 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章