Unfortunately, you cannot use the $ operator more than once for each key, so you need to use numeric values ββfor the rest. How in:
db.myCollection.update({ "id": 1, "forecasts.forecast-id": 123, "forecasts.levels.level": "proven", "forecasts.levels.configs.config": "Custom 1" }, {"$set": {"forecasts.$.levels.0.configs.0": newData}} )
MongoDB support for updating nested arrays is poor. Therefore, you should better avoid using them if you need to update data frequently and use multiple collections instead.
One possibility: make forecasts your own collection and assuming that you have a fixed set of level values, make a level object instead of an array:
{ _id: 123, parentId: 1, name: "Forecast 1", levels: { proven: { configs: [ { config: "Custom 1", variables: [{ x: 1, y:2, z:3}] }, { config: "Custom 2", variables: [{ x: 10, y:20, z:30}] }, ] }, likely: { configs: [ { config: "Custom 1", variables: [{ x: 1, y:2, z:3}] }, { config: "Custom 2", variables: [{ x: 10, y:20, z:30}] }, ] } } }
Then you can update it using:
db.myCollection.update({ _id: 123, 'levels.proven.configs.config': 'Custom 1' }, { $set: { 'levels.proven.configs.$': newData }} )