我对mongodb非常陌生,在更新操作中遇到了一些麻烦。下面是文档:Mongodb在子阵列内更新操作
{
"username" : "amitverma",
"notifications" : {
"notification_add_friend" : [
{
"sender" : "macbook",
"action" : "",
"type" : "",
"objectType" : "request",
"objectUrl" : "",
"isUnread" : true
},
{
"sender" : "safari",
"action" : "",
"type" : "",
"objectType" : "request",
"objectUrl" : "",
"isUnread" : true
},
{
"sender" : "chrome",
"action" : "",
"type" : "",
"objectType" : "request",
"objectUrl" : "",
"isUnread" : true
}
]
},
"_id" : ObjectId("526598c86f45240000000001")
}
{
"username" : "macbook",
"notifications" : {
"notification_add_friend" : [
{
"sender" : "amitverma",
"action" : "",
"type" : "",
"objectType" : "a_r",
"objectUrl" : "",
"isUnread" : true
}
]
},
"_id" : ObjectId("526598d06f45240000000002")
}
我想与{"sender":"safari"}
内"username":"amitverma"
我曾尝试$ elemMatch与$集删除子阵列,但就是无法得到正确的查询。
如果我正确理解你,你想从第一个文档中删除整个'notification_add_friend'数组? * P.S。其实这里有两个文件* – Shad
我*认为* OP意味着从阵列中删除“safari”请求,但措辞有点奇怪。如果打算删除整个数组,我将删除/更改我的答案。 – numbers1311407