I am pretty sure how INSERT works in mongodb, but I want insert to insert the data and in case the Id already exists I want to update the data like SAVE in mongodb.
Example:
If my entry in test collection is like,
{ "_id":ObjectId("68768242ge"), "name":"1" }
I know using save am able to update the current data as
db.test.save({ "_id":ObjectId("68768242ge"), "name":"2" })
But the list update is possible only using INSERT query.
db.test.insert({ "_id":ObjectId("68768242ge"), "name":"2" })
I will get an error in this case as a duplicate key.
So I want to do both the operation, If the object is not there, Then I want to insert it but where as if the Object key already exists then I want to update it.
Is there any way through which we can achieve it? I want to do the bulk insert / update using mongodb.
What you want to do is called "upsert".
You can check the MongoDB documentation of db.collection.update().