云函数调用数据库报错,请教报错信息的含义?
我在一个云函数里有大量的数据要插入,由于插入数据库时有request body大小的限制,所以我做了一个循环让数据能够分批插入,但是每次云函数都报错,不太明白报错信息都含义。
const MAXPAYLOAD = 2000000;
let pList = [];
let totalSize = JSON.stringify(vals).length;
if (totalSize < MAXPAYLOAD) {
pList.push(db.collection("testCollection").add({
data:vals
}));
} else {
let percent = Math.floor(MAXPAYLOAD/totalSize*100);
let i = 0;
while (i < vals.length) {
var batchSize = Math.floor(vals.length*percent/100);
var tempList = vals.slice(i, batchSize);
var checkLength = JSON.stringify(tempList).length;
while (checkLength > MAXPAYLOAD) {
batchSize = Math.floor(batchSize * percent / 100);
tempList = vals.slice(i, batchSize);
checkLength = JSON.stringify(tempList).length;
}
tempList = vals.slice(i, batchSize);
i += batchSize;
console.log(batchSize);
pList.push(db.collection("testCollenction").add({
data:tempList
}));
}
}
console.log(pList.length);
let res = await Promise.all(pList);
报错信息如下: