I want to update by pushing new fields to an existing dictionary object inside a list. For example, the current structure looks like:
[
{
_id: 1 ,
name: 'example',
info: [
{ num: '123' },
{ num: '456' },
],
}
]
Say I want to add new fields like “age” and “address” specifically to the dict where num = “123”.
So, I would want something like:
info: [
{ num: '123' , age: 32, address: "xyz" },
{ num: '456' },
]
How would I go about this?
I’ve looked at MongoDB 4.2 update pipeline: “Push or Update” in nested array but found it difficult to understand. I would really appreciate explanations on how to do something like this. Thanks in advance.