我有一个集合:
//the json.
{
"ItemsToDelete" : [
{
"placeId" : "ChIJIQBpAG2ahYAR_6128GcTUEo",
"users" : [
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15")
]
},
{
"placeId" : "ChIJIQBpAG2ahYAR_6128GcTUEo",
"users" : [
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15")
]
},
{
"placeId" : "ChIJIQBpAG2ahYAR_6128GcTUEo",
"users" : [
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15")
]
}
]
}
{
"ItemsToRemove" : [
{
"ChIJIQBpAG2ahYAR_6128GcTUEo" : [
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15")
]
},
{
"ChIJIQBpAG2ahYAR_6128GcTUEo" : [
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15")
]
},
{
"ChIJIQBpAG2ahYAR_6128GcTUEo" : [
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15"),
ObjectId("547e4650f3fb0a022110af15")
]
}
]
}
然后我运行这个 mongo shell 查询从数组中拉出一个项目并删除:
db.users.update({"_id":ObjectId("54e664c4e7c3b4d3b5413e39")},{$pull:{ItemsToDelete : {placeId:"ChIJIQBpAG2ahYAR_6128GcTUE"}}},{ multi: true })
数组保持不变。任何想法为什么这不能 $pull?
我已经尝试过“ItemsToDelete.placeId”,但出现错误:执行“ItemsToDelete.placeId”时收到的错误=>“无法使用部件(ItemsToDelete.placeId 的ItemsToDelete)遍历元素”
天涯尽头无女友
相关分类