0
我有一個名爲notification
的集合中的文檔,如下所示。MonogoDB:如何替換數組的對象元素
{
"_id" : ObjectId("56438985e68a78f46b1fd9cc"),
"modulename" : "Admin Control Panel",
"modulecode" : "acp",
"eventnames" : [
{
"name" : "New user account added",
"code" : 100,
"_id" : ObjectId("5655fb5d710557d8f7895d94"),
"emails" : [
"[email protected]"
]
},
{
"name" : "User permissions changes",
"code" : 200,
"_id" : ObjectId("5655fb5d710557d8f7895d93"),
"emails" : [
"[email protected]",
"[email protected]",
"[email protected]"
]
}
]
}
我想從eventnames
數組與另一對象替換一個對象。比方說,要與下列對象
{
"name" : "New user account added",
"code" : 100,
"_id" : ObjectId("5655fb5d710557d8f7895d94"),
"emails" : [
"[email protected]"
],
"template": {
"title": "Test Email Title",
"body": "Test Email Body"
}
}
我怎麼能做到這一點,以取代下列對象
{
"name" : "New user account added",
"code" : 100,
"_id" : ObjectId("5655fb5d710557d8f7895d94"),
"emails" : [
"[email protected]"
]
},
。謝謝。
的可能的複製[MongoDB的 - 更新中嵌套的數組的對象(http://stackoverflow.com/questions/10522347/mongodb-update-an-object-在嵌套陣列) – joao