我有这样的模型:
{
"_id":"5b90eea8c02e062be2888446",
"storeGuid":"e97d4730-9b8a-49ed-be87-caf4054439aa",
"storeId":"0",
"storeDbName":"0",
"tenant":"dev",
"configGroup":[
{
"groupName":"peopleCounter",
"config":[
{
"key":"averageWaitPeriodTime",
"value":"60",
}
]
},
{
"groupName":"sessionMonitor",
"config":[
{
"key":"testKey1",
"value":"987",
},
{
"key":"testKey2",
"value":"123",
}
]
}
]
}
我正在尝试更新value
for "key":"testKey2"
我有这样的更新声明:
await coll.UpdateOneAsync(
x => x.StoreGuid == storeGuid
&& x.ConfigGroup.Any(y => y.GroupName == groupName
&& y.Config.Any(z => z.Key == model.Key)),
Builders<StoreModel>.Update.Set(x => x.ConfigGroup[-1].Config[-1].Value, model.Value));
例如,当我尝试更新时groupName
使用这样的过滤器ConfigGroup[-1]
有用。
但在这种情况下,当我们有ConfigGroup[-1].Config[-1]
这是行不通的。
我知道如何更新值的两个选项:
- 只需使用更新整个列表
ConfigGroup[-1].Config
- 或者为过滤器指定具体索引,例如
ConfigGroup[configGroupIndex].Config[configKeyIndex].Value
但我想知道为什么它不起作用-1
指数。
以及如何正确地做到这一点。
请使用以下方式回答时间:2019-03-17 标签:c#MongoDB.Driver.
提前致谢。