我的文档结构
{
"_id": { "$oid" : "512F57222F2A936C3300198E" },
"createdAt": { "$date": 1362056994000.000000 },
"level": null,
"levelAchievements": [
],
"points": 1,
"profile": null,
"progresses": [
{
"behavior": {
"_id": { "$oid" : "511D058E52FBF0FD25000004" },
"name": "Active User",
"key": "ActiveUser",
"points": 0,
"timeout": 0
},
"behaviorCount": 1,
"behaviorParameter": null,
"userId": null,
"modifiedAt": { "$date": 1362056994000.000000 },
"createdAt": { "$date": 1362056994000.000000 },
"behaviorType": "user"
},
{
"behavior": {
"name": "Mur (1)",
"points": 1,
"timeout": 0,
"_id": { "$oid" : "512F4EADA674A86833000006" }
},
"behaviorCount": 1,
"behaviorParameter": null,
"userId": null,
"modifiedAt": { "$date": 1362056994000.000000 },
"createdAt": { "$date": 1362056994000.000000 },
"behaviorType": "user"
},
{
"behavior": {
"_id": { "$oid" : "511D052F52FBF0FD25000002" },
"disabled": false,
"name": "Unity Installed",
"key": "UnityInstalled",
"points": 0,
"timeout": 0
},
"behaviorCount": 1,
"behaviorParameter": null,
"userId": null,
"modifiedAt": { "$date": 1362056994000.000000 },
"createdAt": { "$date": 1362056994000.000000 },
"behaviorType": "user"
}
],
"trophyAchievements": [
],
"userId": "1022082379"
}
我正在尝试删除progress.behavior.name等于“Mur(1)”的数组节点,我尝试了这个查询,但它不起作用。
db.users.update({},{$pull : { "progresses" : { "behavior" : { "name" : "Mur (1)" }}}});
db.users.update({}, { $pull : {"progresses.behavior.name" : "Mur (1)"} }, false, true );
答案 0 :(得分:1)
这个有效:
db.users.update({"progresses.behavior.name" : "Mur (1)"}, { $pull : {"progresses" : { "behavior.name" : "Mur (1)"} } }, false, true );