"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Error: errCode: -501001 resource system error | errMsg: collection.update:fail ESOCKETTIMEDOUT; at collection.update api;
at returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6187:16)
at Object.returnAsFinalCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6201:15)
at /var/user/node_modules/wx-server-sdk/index.js:1466:32
at processTicksAndRejections (node:internal/process/task_queues:96:5)","statusCode":430
采用分批执行+替换新的Database对象,例如
//分批执行 for (let attrList of listArr) { //每隔15个attrList就从新生成一个新的dbTemp cloud.database({ throwOnNotFound: false }) //一个attrList 是15条数据,每15个attrList 也就是15*15个之后换一个新的dbTemp if(num === 15){ num = 0 dbTemp = cloud.database({ throwOnNotFound: false }) console.log(`更换DB对象${dbTemp.toString()}`) }else{ num++ } await dbTemp.runTransaction(async transaction => { const goodsOrderTDB = transaction.collection('order'); const userTDB = transaction.collection('user'); //遍历数组,每个数组调用批量插入 try { for (const order of attrList) { //执行单个逻辑... console.log(`新增第${count}条数据`); count++ } // 提交事务 console.log('事务成功提交'); } catch (err) { console.error("事务异常:", err); console.log(`一共新增数据${count}条`); transaction.rollback(-100); return Promise.reject(err); // 事务失败,返回错误 } }); } //如果能找到dbtemp关闭方法就更完美了
解决了吗