Mongodb – Upsert many documents based on _id
I need to upsert many documents based on _id. E.g. document_1 = {_id:"1", "age":11, "name":"name1"} document_2 = {_id:"2", "age":22, "name":"name2"} I wrote the below db.my_collection.updateMany( { _id: {"$in":["1","2"] } }, [ {$set: {_id:"1", "age":11, "name":"name1"}}, {$set: {_id:"2", "age":22, "name":"name2"}} ],…