我在Mongo中有这份数据:
{
"_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"}
我该如何在Mongo中操作?
据我所知,操作符只能支持第一个数组,有人建议使用子子数组元素的索引,但问题是如何在运行时知道那个索引?(我正在使用MongoDB的本机C#驱动程序)
提前感谢您的帮助!
Johnny