我有這樣的數據,蒙戈:更新子陣列的子元素MongoDB中
{
"_id" : ObjectId("505fd43fdbed3dd93f0ae088"),
"categoryName" : "Cat 1",
"services" : [
{
"serviceName" : "Svc 1",
"input" : [
{ "quantity" : 10, "note" : "quantity = 10" },
{ "quantity" : 20, "note" : "quantity = 20" }
]
},
{
"serviceName" : "Svc 2",
"input" : [
{ "quantity" : 30, "note" : "quantity = 30" },
{ "quantity" : 40, "note" : "quantity = 40" }
]
}
]
}
現在我想更新數量爲「SVC 1」:
{ "quantity" : 10, "note" : "quantity = 10" }
像:
{"quantity": 100, "note": "changed to 100"}
我如何做蒙戈?`
正如我硝酸鉀w,運算符只支持第一個數組,有人建議使用sub sub數組元素的索引,但問題是如何在運行時知道該索引? (我使用的是MongoDB的原生C#驅動程序)
在此先感謝您的幫助!
約翰尼
有子文檔,這非常有用是在MongoDB問題跟蹤器中的相關請求[SERVER-267](https://jira.mongodb.org/browse/SERVER-267)(部分通配符支持)。 – Stennie
感謝您的幫助,Stennie!我目前將輸入和輸出數組分組到另一個集合中作爲解決方法。 – Johnny