我有这样的数据,蒙戈:更新子阵列的子元素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