var fff
for (let info of data) {
fff = Math.floor(Math.random()*2);
var res = await db.collection('test').where({_id:info.uid}).update({view:dbCmd.inc(fff)})
if(res.updated){
console.log("更新成功",res);
}else{
console.log("更新失败",res);
}
}
![易赚科技](https://img-cdn-tc.dcloud.net.cn/account/identicon/a68039223676919529b3ae3de6eac1a7.png)
- 发布:2023-02-17 23:02
- 更新:2023-02-20 11:25
- 阅读:252
产品分类: uniCloud/App
示例代码:
操作步骤:
var fff
for (let info of data) {
fff = Math.floor(Math.random()*2);
var res = await db.collection('test').where({_id:info.uid}).update({view:dbCmd.inc(fff)})
if(res.updated){
console.log("更新成功",res);
}else{
console.log("更新失败",res);
}
}
var fff
for (let info of data) {
fff = Math.floor(Math.random()*2);
var res = await db.collection('test').where({_id:info.uid}).update({view:dbCmd.inc(fff)})
if(res.updated){
console.log("更新成功",res);
}else{
console.log("更新失败",res);
}
}
预期结果:
全部更新成功
全部更新成功
实际结果:
部分成功部分失败
部分成功部分失败
bug描述:
for循环内使用update更新数据,有的成功有的不成功
22:54:53.450 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:53.593 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:53.763 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:53.901 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:54.094 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:54.254 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:54.433 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:54.623 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:54.773 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:54.943 [本地运行]更新成功 {"affectedDocs":1,"updated":1} uniCloud-aliyun/cloudfunctions/cron-view/index.js:28:11
22:54:55.100 [本地运行]更新成功 {"affectedDocs":1,"updated":1} uniCloud-aliyun/cloudfunctions/cron-view/index.js:28:11
22:54:55.243 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:55.400 [本地运行]更新成功 {"affectedDocs":1,"updated":1} uniCloud-aliyun/cloudfunctions/cron-view/index.js:28:11
22:54:55.563 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:55.724 [本地运行]更新成功 {"affectedDocs":1,"updated":1} uniCloud-aliyun/cloudfunctions/cron-view/index.js:28:11
22:54:55.883 [本地运行]更新成功 {"affectedDocs":1,"updated":1} uniCloud-aliyun/cloudfunctions/cron-view/index.js:28:11
22:54:56.037 [本地运行]更新成功 {"affectedDocs":1,"updated":1} uniCloud-aliyun/cloudfunctions/cron-view/index.js:28:11
22:54:56.182 [本地运行]更新失败 {"affectedDocs":0,"updated":0} uniCloud-aliyun/cloudfunctions/cron-view/index.js:30:11
22:54:56.367 [本地运行]更新成功 {"affectedDocs":1,"updated":1} uniCloud-aliyun/cloudfunctions/cron-view/index.js:28:11
22:54:56.545 [本地运行]更新成功 {"affectedDocs":1,"updated":1} uniCloud-aliyun/cloudfunctions/cron-view/index.js:28:11
易赚科技 (作者)
id存在,data数据我是从云端获取的
2023-02-22 17:01
DCloud_uniCloud_CRL
回复 易赚科技: data打印出来看一下,看日志显示的是没匹配到要修改的文档。
2023-02-23 11:12