我在云函数里写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
}
}
}