I have such model:
{
"_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",
}
]
}
]
}
I am trying to update value
for "key":"testKey2"
I have such update statement:
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));
When i try to update for example groupName
using such filter ConfigGroup[-1]
it works.
But in the case when we have ConfigGroup[-1].Config[-1]
it does not work.
I know two options how to update the value:
- just update whole list using
ConfigGroup[-1].Config
- or specify concrete indexes for filter like
ConfigGroup[configGroupIndex].Config[configKeyIndex].Value
But i want to know why it does not work with -1
index.
And how to do it properly.
Please answer using c# MongoDB.Driver.
Thanks in advance.