INVALID_ARGUMENT:每个请求最多允许 500 次写入

我正在尝试在Firebase云函数中运行以下代码。我尝试做的是遍历名为 savedData 的 Firestore 集合中的所有文档,解析存储在每个文档中的字符串的 JSON,然后将解析后的数据存储到名为 stgPicks 的集合中的新文档中。保存的数据收集集合中的每个文档应在 stgPicks 集合中创建 50-100 个新文档。


当我尝试运行该函数时,我得到以下错误代码。


任何人都可以帮助调试此代码吗?我不确定我是否正确处理了批处理。


Error: 3 INVALID_ARGUMENT: maximum 500 writes allowed per request

    at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:30:26)

    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:175:52)

    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)

    at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)

    at Http2CallStream.outputStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:115:74)

    at Http2CallStream.maybeOutputStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:154:22)

    at Http2CallStream.endCall (/workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:140:18)

    at Http2CallStream.handleTrailers (/workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:265:14)

    at ClientHttp2Stream.emit (events.js:198:13)

    at ClientHttp2Stream.EventEmitter.emit (domain.js:466:23)

exports.parsePicksRecover = functions.https.onRequest((req, res) => {

  let savedDataRef = admin.firestore().collection('savedData')

  let allDrafts = savedDataRef

    .get()

    .then((snapshot) => {

      snapshot.forEach((doc) => {

        const docId = doc.id

        const getDoc = admin

          .firestore()

          .collection('savedData')

          .doc(`${docId}`)

          .get()

          .then((doc) => {

            if (!doc.exists) {

              console.log('No matching document.')

            } 

炎炎设计
浏览 138回答 1
1回答

慕工程0101907

我确实在使用PHP SDK时遇到了相同的错误,在我的情况下,问题是在提交之后,我需要创建一个新的实例,我认为它会尝试提交旧文档更改两次,这就是为什么你遇到每个请求允许的最大500次写入错误,例如:batchlet batch = admin.firestore().batch();for (i = 1; i <= 10000; ++i) {&nbsp; &nbsp; &nbsp;// do something with the batch&nbsp; &nbsp; &nbsp;if (0 === i % 500) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; batch.commit();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; batch = admin.firestore().batch();&nbsp; &nbsp; &nbsp;}}batch.commit();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript