lib/operations/collection_ops.js
function save(coll, doc, options, callback) {
  // Get the write concern options
  const finalOptions = applyWriteConcern(
    Object.assign({}, options),
    { db: coll.s.db, collection: coll },
    options
  );
  // Establish if we need to perform an insert or update
  if (doc._id != null) {
    finalOptions.upsert = true;
    return updateDocuments(coll, { _id: doc._id }, doc, finalOptions, callback);
  }

  // Insert the document
  insertDocuments(coll, [doc], finalOptions, (err, result) => {
    if (callback == null) return;
    if (doc == null) return handleCallback(callback, null, null);
    if (err) return handleCallback(callback, err, null);
    handleCallback(callback, null, result);
  });
}
function save(coll, doc, options, callback) {
  // Get the write concern options
  const finalOptions = applyWriteConcern(
    Object.assign({}, options),
    { db: coll.s.db, collection: coll },
    options
  );
  // Establish if we need to perform an insert or update
  if (doc._id != null) {
    finalOptions.upsert = true;
    return updateDocuments(coll, { _id: doc._id }, doc, finalOptions, callback);
  }

  // Insert the document
  insertDocuments(coll, [doc], finalOptions, (err, result) => {
    if (callback == null) return;
    if (doc == null) return handleCallback(callback, null, null);
    if (err) return handleCallback(callback, err, null);
    handleCallback(callback, null, result);
  });
}
function save ( coll , doc , options , callback ) { // Get the write concern options const finalOptions = applyWriteConcern ( Object . assign ( { } , options ) , { db : coll . s . db , collection : coll } , options ) ; // Establish if we need to perform an insert or update if ( doc . _id != null ) { finalOptions . upsert = true ; return updateDocuments ( coll , { _id : doc . _id } , doc , finalOptions , callback ) ; } // Insert the document insertDocuments ( coll , [ doc ] , finalOptions , ( err , result ) => { if ( callback == null ) return ; if ( doc == null ) return handleCallback ( callback , null , null ) ; if ( err ) return handleCallback ( callback , err , null ) ; handleCallback ( callback , null , result ) ; } ) ; }
Save a document.

@method
@param {Collection} a Collection instance.
@param {object} doc Document to save
@param {object} [options] Optional settings. See Collection.prototype.save for a list of options.
@param {Collection~writeOpCallback} [callback] The command result callback
@deprecated use insertOne, insertMany, updateOne or updateMany
Save a document .