如何更新非常大的 firestore 集合

How to update very large firestore collection

我需要通过 node.js 的 admin sdk 为 Firestore 中一个非常大的集合的每个文档添加一个字段。一些文档已经有该字段,所以我需要在 setting/updating 之前检查它的值。该集合大约有 150k 个文档。即使尝试使用以下代码获取文档也会超时。

  const documents = await db.collection('collectionName').get()

是否有处理非常大的集合的特殊方法?

您应该使用在之前的查询中看到的 pagination in order to avoid loading all the documents into memory with a single query. This will let you process documents in batches by specifying the last document snapshot 来进行新的查询以获取下一页数据。

您需要在每个查询上放置一个合理的 limit 以确保您在每个页面中获得合理数量的文档。