here is my data which I need to add in a collection
let data = {
'a':'data a',
'ab':'data a',
'b':'data b',
'c':'data c'
}
here is my collection data:
{
name:'xyz',
age:'100',
arr: ['a','ab']
}
what I want:
{
name:'xyz',
age:'100',
arr: ['a','ab'],
data:'data a' //get this from arr first element, and that is key in data object that's value here
}
can someone help me to write this query to add new field in all documents ?
here is get query for same But, this time I want to insert data in all documents.
2
Answers
you can add aggregation query in update only.
if you need to update multiple documents then you have to pass {multi:true}.
mongoplayground