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