我不得不ArrayList中特定文檔的要求MongoDB中的陣列的文檔時,用於該樣品JSON字符串是更新在使用webMethods
{ 「_id」:的ObjectId(「58b9339502be203f6b476664」), 「_docType」: 「測試」, 「類型」: 「mongoUpdate」,
"createdDateTime" : "2017-03-03 09:12:53.080",
"contacts" : [
{
"firstName" : "FirstName",
"lastName" : "LastName",
"email" : "[email protected]",
"contactType" : "Business.",
"phoneNumber" : "1234567890",
"createdDateTime" : "2017-03-03 09:13:04.229",
"lastModifiedDTM" : "2017-03-03 09:13:04.229",
},
{
"firstName" : "FirstName2",
"lastName" : "LastName2",
"email" : "[email protected]",
"contactType" : "Business2.",
"phoneNumber" : "1234567890",
"createdDateTime" : "2017-03-03 09:13:04.229",
"lastModifiedDTM" : "2017-03-03 09:13:04.229",
},
{
"firstName" : "FirstName3",
"lastName" : "LastName3",
"email" : "[email protected]",
"contactType" : "Business.3",
"phoneNumber" : "12345678903",
"createdDateTime" : "2017-03-03 09:13:04.229",
"lastModifiedDTM" : "2017-03-03 09:13:04.229",
}
]
}
說我有更新在上述JSON發生中的一個。 我已經使用$ set操作來更新上面的數組,並且當我看到mongo數據庫中的內容時,我看到整個數組被替換爲單次發生的聯繫。
我所使用的更新命令是
{$組:{ 「接觸」:[{ 「名字」: 「test0103)12」, 「姓氏」: 「test0103」, 「電子郵件」:」 test0103「,」contactType「:」test0103「,」phoneNumber「:」test0103「,」createdDateTime「:」test0103「}]}}
執行此操作後,我看到整個數組列表3被替換爲單個聯繫人實例。
並在結束我有輸出作爲 「接觸」:[{
"firstName" : "test0103)12",
"lastName" : "test0103",
"email" : "test0103",
"contactType" : "test0103",
"phoneNumber" : "test0103",
"createdDateTime" : "test0103"
}]
那是因爲你不要像你在做的那樣更新對象的數組。數組內對象的操作在貓鼬中完成的方式不同,並且有許多與它有關的問題,您可以發現它們。 –