Just like SQL Mongo also has a bulk update command. It's as simple as -
db.getCollection('<name>').bulkWrite
([
{
updateOne:
{
filter: {<your-condition>},
update: {<what-you-want-to-update>
}
}
]);
And the updateOne block can be repeated "n" times.
If you are trying to update from an excel file, use the CONCATENATE().
Here is a sample -
=CONCATENATE("{updateOne:{filter:{","'brands.brandId'",":'",E2,"'},update:{$set:{","'brands.$.image'",":'",F2,"'}}}},")
I have values in E2 and F2 columns.
Note: Don't forget the last comma in the CONCATENATE(). Since bulkWrite() accepts an array, it will need the jsons comma separated.
Happy coding :D
Top comments (0)