因此,我正在尝试在我的firebase函数中使用批处理写入来以500个批处理的批处理我的写入。但是,由于某种原因,我收到错误“错误:无法修改已提交的 WriteBatch”,并且似乎无法发现我做错了什么。它正在存储前几个结果,但之后它在我的云函数日志中给了我错误。任何建议将不胜感激= D
messages.forEach((item, index) => {
var all = _.find(item.parts, { which: "" });
var id = item.attributes.uid;
var idHeader = "Imap-Id: " + id + "\r\n";
// eslint-disable-next-line handle-callback-err
simpleParser(idHeader + all.body, (err, mail) => {
// access to the whole mail object
console.log(mail.subject);
console.log(mail.html);
let newDate = mail.date.valueOf();
batch.set(
docRef,
{
Emails: admin.firestore.FieldValue.arrayUnion(
JSON.stringify({
subject: mail.subject,
body: mail.text,
date: newDate,
from: mail.from,
})
),
//....
},
{ merge: true }
);
if (
(index % 500 === 0 && index > 0) ||
index === messages.length - 1
) {
return batch.commit().then(() => {
return console.log("SUCCESS");
});
}
});
});
慕沐林林
相关分类