我的文檔是這樣的MongoDB:如何從一個文檔中的嵌套數組刪除對象
"page_elements" : [
{
"type" : "gallery",
"words" : [
"gallery",
"photos"
]
},
{
"type" : "cart",
"words" : [
"cart",
"shop"
]
},
{
"type" : "Privacy",
"words" : [
"privacy",
"policy",
"privacy policy"
]
},
{
"type" : "cart",
"words" : [
"cart",
"shopping cart",
"buy now",
"add to cart",
"add to basket"
]
}
錯誤,我已經更新車的兩倍。現在,我需要刪除陣列中的第一個購物車並保留文檔的其餘部分。
在這裏,我需要刪除
{
"type" : "cart",
"words" : [
"cart",
"shop"
]
}
我想這個..
db.ds_master_language_words.remove({ "page_elements.type" : "cart" })
@DanDascalescu不一樣的問題:通過賦予該數組元素匹配,以除去一個
page_elements
值。他只是想刪除**一個**數組元素。這是'.remove()'方法,在這裏是錯誤的。 –