- 我的云函数update问题请帮助?
我在云函数里写update更新数据,里面有多个update语句,只执行第一个,第二个成功后第三个就退出不执行了为什么?我是个菜鸟。 const cloud = require('wx-server-sdk') cloud.init({ env: 'jlccba-0gjdzjbs62e3fd4b', }) const db=cloud.database() const _ = db.command var timestamp = Date.parse(new Date()); var date = new Date(timestamp); var thisyear=date.getFullYear(); // 云函数入口函数 exports.main = async (event, context) => { try { // 遍历修改数据库信息 for (let i = 0; i < event.data.length; i++) { console.log(event.data) 第一个: db.collection('match').where({ _id: event.data[i]._id }).update({ data: { mth_results_primary: event.data[i].mth_results_primary, mth_results_second: event.data[i].mth_results_second, mth_finish_flag:'1', }, }) if(event.data[i].mth_results_primary !=0 || event.data[i].mth_results_second!=0){ if (event.data[i].mth_results_primary>event.data[i].mth_results_second){ 第二个 await db.collection(thisyear.toString()).where({teamname:event.data[i].mth_name_primary}).update({ data:{ t_absolute_score:_.inc(event.data[i].mth_results_primary-event.data[i].mth_results_second), t_victory:_.inc(1), t_score:_.inc(2) } }) 第三个 await db.collection(thisyear.toString()).where({teamname:event.data[i].mth_name_second}).update({ data:{ t_absolute_score:_.inc(event.data[i].mth_results_second-event.data[i].mth_results_primary), t_lost:_.inc(-1), t_score:_.inc(1) } }) }else{ await db.collection(thisyear.toString()).where({teamname:event.data[i].mth_name_second}).update({ data:{ t_absolute_score:_.inc(event.data[i].mth_results_second-event.data[i].mth_results_primary), t_victory:_.inc(1), t_score:_.inc(2) } }) console.log('问问:'+event.data[i].mth_name_primary) await db.collection(thisyear.toString()).where({teamname:event.data[i].mth_name_primary}).update({ data:{ t_absolute_score:_.inc(event.data[i].mth_name_primary-event.data[i].mth_name_second), t_lost:_.inc(-1), t_score:_.inc(1) } }) console.log('我我:'+event.data[i].mth_name_primary) } } } return { success: true, data: event.data } } catch (e) { return { success: false, errMsg: e } } }
2021-06-07 - 云函数update多个集合出现问题?
云函数进行循环update数据,只进行一个集合update可以,如果同时进行另外一个集合update就不可以。为什么请看代码// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init({ env: 'jlccba-0gjdzjbs62e3fd4b', }) const db=cloud.database() const _ = db.command var timestamp = Date.parse(new Date()); var date = new Date(timestamp); var thisyear=date.getFullYear(); // 云函数入口函数 exports.main = async (event, context) => { try { // 遍历修改数据库信息 for (let i = 0; i < event.data.length; i++) { console.log(event.data) db.collection('match').where({ _id: event.data[i]._id }).update({ data: { mth_results_primary: event.data[i].mth_results_primary, mth_results_second: event.data[i].mth_results_second, mth_finish_flag:'1', }, }) if(event.data[i].mth_results_primary !=0 || event.data[i].mth_results_second!=0){ if (event.data[i].mth_results_primary>event.data[i].mth_results_second){ db.collection(thisyear.toString()).where({teamname:event.data[i].mth_name_primary}).update({ data:{ t_absolute_score:_.inc(event.data[i].mth_results_primary-event.data[i].mth_results_second), t_victory:_.inc(1), t_score:_.inc(2) } }) db.collection(thisyear.toString()).where({teamname:event.data[i].mth_name_second}).update({ data:{ t_absolute_score:_.inc(event.data[i].mth_results_second-event.data[i].mth_results_primary), t_lost:_.inc(-1), t_score:_.inc(1) } }) }else{ db.collection(thisyear.toString()).where({teamname:event.data[i].mth_name_second}).update({ data:{ t_absolute_score:_.inc(event.data[i].mth_results_second-event.data[i].mth_results_primary), t_victory:_.inc(1), t_score:_.inc(2) } }) db.collection(thisyear.toString()).where({teamname:event.data[i].mth_name_primary}).update({ data:{ t_absolute_score:_.inc(event.data[i].mth_name_primary-event.data[i].mth_name_second), t_lost:_.inc(-1), t_score:_.inc(1) } }) } } } return { success: true, data: event.data } } catch (e) { return { success: false, errMsg: e } } }
2021-06-07 - 发起云存储为什么会提示“列表是空的, 因为发生了错误。”报错?
数据加载失败几秒前 加载 “cosListBucket” 失败:{"error":{"Code":"PaymentRequired","Message":"The action performed on your resource is not allowed for now, please check the quota of your package.","Resource":"6a6c-jlccba-0gjdzjbs62e3fd4b-1305934875.cos.ap-shanghai.myqcloud.com","RequestId":"NjBiYzQ1NTdfYTM5ZjA4MDlfMmVjNF9iN2RiYWY=","TraceId":"OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTBjYzE2MjAxN2M1MzJiOTdkZjMxMDVlYTZjN2FiMmI0MTA2MzlhODljYTgwODczMTAzZGU1OGMxZmY5YzExYjI="},"statusCode":402,"headers":{"connection":"keep-alive","content-length":"559","content-type":"application/xml","date":"Sun, 06 Jun 2021 03:47:35 GMT","server":"tencent-cos","x-cos-request-id":"NjBiYzQ1NTdfYTM5ZjA4MDlfMmVjNF9iN2RiYWY=","x-cos-trace-id":"OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTBjYzE2MjAxN2M1MzJiOTdkZjMxMDVlYTZjN2FiMmI0MTA2MzlhODljYTgwODczMTAzZGU1OGMxZmY5YzExYjI="}}
2021-06-06 - 发起云存储请求为什么会提示“列表是空的, 因为发生了错误。”报错?
加载 “cosListBucket” 失败:{"error":{"Code":"PaymentRequired","Message":"The action performed on your resource is not allowed for now, please check the quota of your package.","Resource":"6a6c-jlccba-0gjdzjbs62e3fd4b-1305934875.cos.ap-shanghai.myqcloud.com","RequestId":"NjBiYWI3NjVfMWM5ZDA4MDlfMzExYl9iMDJjMTE=","TraceId":"OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTBjYzE2MjAxN2M1MzJiOTdkZjMxMDVlYTZjN2FiMmI0MTA2MzlhODljYTgwODczMTAzZGU1OGMxZmY5YzExYjI="},"statusCode":402,"headers":{"connection":"keep-alive","content-length":"559","content-type":"application/xml","date":"Fri, 04 Jun 2021 23:29:41 GMT","server":"tencent-cos","x-cos-request-id":"NjBiYWI3NjVfMWM5ZDA4MDlfMzExYl9iMDJjMTE=","x-cos-trace-id":"OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTBjYzE2MjAxN2M1MzJiOTdkZjMxMDVlYTZjN2FiMmI0MTA2MzlhODljYTgwODczMTAzZGU1OGMxZmY5YzExYjI="}}
2021-06-05