I have a document which is structured like this
{ vendor_id:534534
ItemList:[
{"Brand": "Apple","Product": "iPad"},
{"Brand": "Samsung","Product": "Galaxy"},
{"Brand": "Apple","Product": "iPhone"}
]
}
I want to update the document in my array ItemList, to add a new field say model to only one particular document to make my document look like
{ vendor_id:534534
ItemList:[
{"Brand": "Apple","Product": "iPad","Model":"Air2"},
{"Brand": "Samsung","Product": "Galaxy"},
{"Brand": "Apple","Product": "iPhone"}
]
}
I know using $addToSet/$push can directly add to the array itself, but how to add can I add it to the document within the array.
This is different because you don't have a key to identify which document in the array you need to update. If there happens to be a key, I too know the answer :)