我在云函数中有以下代码,它返回错误信息
Error: 3 INVALID_ARGUMENT: maximum 500 writes allowed per request
console.log(`${projectId} doClassifySources: Got ${_.size(output)} items`)
const lastClassification = new Date().toJSON()
const batch = firestore.batch()
batch.update(projectRef, {lastClassification})
_.forEach(output, item => {
batch.set(projectRef.collection('output').doc(encodeURIComponent(item.url)), {
classifiedAt: admin.firestore.FieldValue.serverTimestamp(),
...item
}, {
merge: true
})
})
return batch.commit().then(() => lastClassification)
然而,在抛出错误之前,firebase 日志显示了这一点:
12:28:19.963 PM classifySources ZklZYB5hq96J43CroKgP doClassifySources: Got 310 items
在我看来,该批处理应包含 310 件元素,远低于 500 件的限制。我是否遗漏了 500 项限制的计算方式? merge: true
是否以任何方式影响它?是否与正在写入的对象中的 item
的传播有关(即,这是否会增加所需的写入次数)?
最佳答案
通过一些额外的测试,似乎使用 admin.firestore.FieldValue.serverTimestamp()
算作额外的“写入”。使用上面的代码,我被限制为 249 个项目(即当 output.length >= 250
时,代码将失败并显示该错误消息。如果我删除对 serverTimeStamp( )
,我每次写入最多可以获得 499 个项目。
我在任何地方都找不到这个文档,也许它是 firebase 库中的一个错误,所以我会在那里发布一个问题,看看会发生什么。
关于javascript - Firestore 批量写入中的 500 个项目限制有何影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54671543/