炎炎設(shè)計(jì)
2022-08-04 17:20:19
我正在嘗試在Firebase云函數(shù)中運(yùn)行以下代碼。我嘗試做的是遍歷名為 savedData 的 Firestore 集合中的所有文檔,解析存儲(chǔ)在每個(gè)文檔中的字符串的 JSON,然后將解析后的數(shù)據(jù)存儲(chǔ)到名為 stgPicks 的集合中的新文檔中。保存的數(shù)據(jù)收集集合中的每個(gè)文檔應(yīng)在 stgPicks 集合中創(chuàng)建 50-100 個(gè)新文檔。當(dāng)我嘗試運(yùn)行該函數(shù)時(shí),我得到以下錯(cuò)誤代碼。任何人都可以幫助調(diào)試此代碼嗎?我不確定我是否正確處理了批處理。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.') }
1 回答

慕工程0101907
TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊
我確實(shí)在使用PHP SDK時(shí)遇到了相同的錯(cuò)誤,在我的情況下,問(wèn)題是在提交之后,我需要?jiǎng)?chuàng)建一個(gè)新的實(shí)例,我認(rèn)為它會(huì)嘗試提交舊文檔更改兩次,這就是為什么你遇到每個(gè)請(qǐng)求允許的最大500次寫入錯(cuò)誤,例如:batch
let batch = admin.firestore().batch();
for (i = 1; i <= 10000; ++i) {
// do something with the batch
if (0 === i % 500) {
batch.commit();
batch = admin.firestore().batch();
}
}
batch.commit();
添加回答
舉報(bào)
0/150
提交
取消