不删除嵌入文档 mongo
not deleted embadded document mongo
我有这个数据:
db.school.find({})
{
"_id" : ObjectId("5a897f6c49bf66c10a70ed0d"),
"first_name" : "Jaskaran",
"last_name" : "singh",
"age" : 30.0
}
{
"_id" : ObjectId("5a897f6c49bf66c10a70ed0f"),
"first_name" : "Amrit",
"last_name" : "singh",
"age" : 31.0
}
{
"_id" : ObjectId("5a897f6c49bf66c10a70ed0e"),
"first_name" : "Vikas",
"last_name" : "Sharma",
"age" : 31.0,
"Address" : {
"Pincode" : 1234.0
}
}
我想删除密码
$pull 不工作!!
db.school.update(
{
'_id':ObjectId("5a897f6c49bf66c10a70ed0e")
},
{ $pull: {
Address: {
Pincode:1 }
} },
{ multi:true }
);
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
db.school.update({}, {$pull:{ "Address": {$elemMatch: {Pincode :1234 } }}})
$pull
用于数组,而您尝试操作 sub-document.
方法是使用 $unset
:
db.school.update({"Address.Pincode" : 1234}, { $unset: { "Address.Pincode" : "" } })
密码 1234。删除每个密码:
db.school.update({}, { $unset: { "Address.Pincode" : "" } })
我有这个数据:
db.school.find({})
{
"_id" : ObjectId("5a897f6c49bf66c10a70ed0d"),
"first_name" : "Jaskaran",
"last_name" : "singh",
"age" : 30.0
}
{
"_id" : ObjectId("5a897f6c49bf66c10a70ed0f"),
"first_name" : "Amrit",
"last_name" : "singh",
"age" : 31.0
}
{
"_id" : ObjectId("5a897f6c49bf66c10a70ed0e"),
"first_name" : "Vikas",
"last_name" : "Sharma",
"age" : 31.0,
"Address" : {
"Pincode" : 1234.0
}
}
我想删除密码
$pull 不工作!!
db.school.update(
{
'_id':ObjectId("5a897f6c49bf66c10a70ed0e")
},
{ $pull: {
Address: {
Pincode:1 }
} },
{ multi:true }
);
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
db.school.update({}, {$pull:{ "Address": {$elemMatch: {Pincode :1234 } }}})
$pull
用于数组,而您尝试操作 sub-document.
方法是使用 $unset
:
db.school.update({"Address.Pincode" : 1234}, { $unset: { "Address.Pincode" : "" } })
密码 1234。删除每个密码:
db.school.update({}, { $unset: { "Address.Pincode" : "" } })