mongoose+koa2 按照_id更新多条数据,删除数组中的字段,然后添加新的字段,$pull和$or结合使用


await model.photo.update({
_id: {
$in: photoIdsParam
}
}, {
$pull: {
customerIds: {
code: custCode,
$or: [{
'userIds.0': {
$exists: false
}
}, {
'userIds.0': ctx.user.userid
}]
}
}
}, {
multi: true
})

await model.photo.update({
_id: {
$in: photoIdsParam
}
}, {
$addToSet: {
customerIds: {
userIds: ctx.user.userid,
code: custCode,
isDel: 'true'
}
}
}, {
upsert: true,
multi: true
})


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM