0
我有如下蒙戈文件:是否可以在mongo文檔中將對象列表添加到嵌入的數組文檔中?
{
"_id" : ObjectId("506e9e54a4e8f51423679428"),
"description" : "ffffffffffffffff",
"menus" : [
{
"_id" : ObjectId("506e9e5aa4e8f51423679429"),
"description" : "ffffffffffffffffffff",
"items" : [
{
"name" : "xcvxc",
"description" : "vxvxcvxc",
"text" : "vxcvxcvx",
"menuKey" : "0",
"onSelect" : "1",
"_id" : ObjectId("506e9f07a4e8f5142367942f")
} ,
{
"name" : "abcd",
"description" : "qqq",
"text" : "qqq",
"menuKey" : "0",
"onSelect" : "3",
"_id" : ObjectId("507e9f07a4e8f5142367942f")
}
]
}
]
}
現在我想改變這:
{
"_id" : ObjectId("506e9e54a4e8f51423679428"),
"description" : "ffffffffffffffff",
"menus" : [
{
"_id" : ObjectId("506e9e5aa4e8f51423679429"),
"description" : "ffffffffffffffffffff",
"items" : {
{
"name" : "xcvxc",
"description" : "vxvxcvxc",
"text" : "vxcvxcvx",
"menuKey" : "0",
"onSelect" : "1",
"_id" : ObjectId("506e9f07a4e8f5142367942f")
} ,
{
"name" : "abcd",
"description" : "qqq",
"text" : "qqq",
"menuKey" : "0",
"onSelect" : "3",
"_id" : ObjectId("507e9f07a4e8f5142367942f")
}
}
}
]
}
這是可能的蒙戈?在第一個模式中,自動更新是不可能的,因爲我們不能在更新深層時使用兩個「$」。所以我想改變架構與第二個一樣,我怎麼能實現它?
因爲我曾用「$推」添加項目內菜單第一個...
任何幫助將是巨大的..
這兩者之間的區別究竟是什麼?在第二個是有一個錯字(字段名稱必須是字符串)?你所說的更新在第一個模式中是不可能的? – Thilo
第二種形式'items'不是有效的Json對象。它必須是一個關鍵值對。 – vivek
@Thilo其實我需要自動更新,例如:我想在項目中更新「名稱」:「abcd」到「名稱」:「cc」。 – user2587222