我對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