Save() method is used to update an existing document or insert a new document depending on its document parameter. A document is a JSON object.
If the document does not contain any _id field, then the
save() method calls the insert() method. During the operation, the mongo shell will create an object and assign it to the _id field. It is to be noted that most MongoDB driver clients will include the _id field and generate an ObjectId before sending the insert operation to MongoDB; however, if the clients send the document without the _id field, the MongoDB will add the _id and generate the ObjectId.
If the document contains an _id field, then the
save() method is equivalent to an update with the upsert option set to true and the query predicate on the _id field.