I have Collection of objects like
[{ key1: 1,
key2: 3,
internal_oject:{
1:'some_value1',
2:'some_value2',
3: 'value3'
}
},
{ key1: 3,
key2: 5,
internal_oject:{
1:'another1',
3: 'another3'
}
}
]
Using aggregation I need to add missed internal_oject.X values ( where X - is value is known in advance(i can bind it in aggregation query)). For example, I already know that X = 2 (I know this key can be missed).
How I can add inside internal_oject add 2:'missed' (maybe using $project)
After executing your aggregation query I expect to see something like this: objects like
[{ key1: 1
key2: 3
internal_oject:{
1:'some_value1'
2:'some_value2'
3: 'value3'
}
},
{ key1: 3
key2: 5
internal_oject:{
1:'another1',
2: 'missed', //<---- must be inserted
3: 'another3'
}
}
]
I find similar issue MongoDB - Projecting a field that doesn't always exist But, I need to add element inside internal object (not root)