云函数操作数据库报错什么原因? 500 Internal error
定时触发的云函数, 总数据700多条,每150条做一次1s的延时,结束会报几条下面的错误。
代码:
const uploadTasks = []
dbUsers.forEach(function (user) {
let key = (user._id) + "-" + dateStr
const promise = tCountLog.add({
data: {
"xxx":"xxx"
},
})
uploadTasks.push(promise)
})
for (i = 0; i < Math.ceil(uploadTasks.length / 150.0); i++) { // 每150条一个循环
const theTasks = uploadTasks.slice(150 * i, Math.min(150 * (i + 1), uploadTasks.length));
log.info({
'title': 'theTasks--theTasks.length=' + theTasks.length
})
await Promise.all(theTasks);
await sleep(1000);
}
return {
data: {},
code: 0,
}
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
报错:
node.js:1 [error] Unhandled Rejection at: Promise {<rejected>: Error: errCode: -1 unknown error | errMsg: collection.add:fail Error:
500 Internal Ser…}__proto__: Promise[[PromiseStatus]]: "rejected"[[PromiseValue]]: Error: errCode: -1 unknown error | errMsg: collection.add:fail Error:
500 Internal Server Error
; at collection.add api;
at returnAsCloudSDKError (/Users/kekejin/Documents/KWAI/KWAI-fans/cloudfunctions/updateCountLog/node_modules/wx-server-sdk/index.js:6086:16)
at Object.returnAsFinalCloudSDKError (/Users/kekejin/Documents/KWAI/KWAI-fans/cloudfunctions/updateCountLog/node_modules/wx-server-sdk/index.js:6100:15)
at /Users/kekejin/Documents/KWAI/KWAI-fans/cloudfunctions/updateCountLog/node_modules/wx-server-sdk/index.js:1198:32
at processTicksAndRejections (internal/process/task_queues.js:85:5) reason: Error: errCode: -1 unknown error | errMsg: collection.add:fail Error:
500 Internal Server Error
; at collection.add api;
at returnAsCloudSDKError (/Users/kekejin/Documents/KWAI/KWAI-fans/cloudfunctions/updateCountLog/node_modules/wx-server-sdk/index.js:6086:16)
at Object.returnAsFinalCloudSDKError (/Users/kekejin/Documents/KWAI/KWAI-fans/cloudfunctions/updateCountLog/node_modules/wx-server-sdk/index.js:6100:15)
at /Users/kekejin/Documents/KWAI/KWAI-fans/cloudfunctions/updateCountLog/node_modules/wx-server-sdk/index.js:1198:32
at processTicksAndRejections (internal/process/task_queues.js:85:5)
_ @ node.js:1
(anonymous) @ node.js:1
emit @ events.js:203
processPromiseRejections @ internal/process/promises.js:201
processTicksAndRejections @ internal/process/task_queues.js:86
internal/process/warning.js:27 (node:26682) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.