I need to update the MongoDB field with the array of objects which has id needs to be updated with same id in the JSON object
if I have some thing like this in MongoDB
{
_id: "adqeer32423twefds",
books : [
{
id : 111,
name: "ABC"
},
{
id : 123,
name: "ABCD"
}
]
}
And I have the JSON data like this to be inserted in Mongo
{
_id: "adqeer32423twefds",
books : [
{
id : 111,
author: "ccc"
},
{
id : 123,
author: "dddd"
}
]
}
After update I need the final data like this in Mongo collection
{
_id: "adqeer32423twefds",
books : [
{
id : 111,
name: "ABC",
author: "ccc"
},
{
id : 123,
name: "ABCD",
author: "dddd"
}
]
}
You can use positional update to do it one by one, and batch those updates using
bulkWrite
.