文档如下
相册
{
"_id" : ObjectId("573ac80afb5f892dac0063e9"),
"pictureSize" : 3,
"pictures" : ["573ac80afb5f892dac0063e6", "573ac80afb5f892dac0063e7", "573ac80afb5f892dac0063e8"],
}
需求 删除多张照片 假设删除 "573ac80afb5f892dac0063e6", "573ac80afb5f892dac0063e7" 这两个 同时 pictureSize -2 为了保证删除内容必须匹配 且 要么此操作都成功 要么都失败
update 语句:
var ws = db.albums.update({_id:ObjectId("573ac80afb5f892dac0063e9"),pictures: { "$all": ["573ac80afb5f892dac0063e7", "573ac80afb5f892dac0063e6"] } },{
$pullAll:{pictures:["573ac80afb5f892dac0063e7", "573ac80afb5f892dac0063e6"]},
$inc:{pictureSize:-2}
})
ps: mongodb 语句 真是黑魔法。。。