lib/operations/collection_ops.js
function replaceOne(coll, filter, doc, options, callback) {
  // Set single document update
  options.multi = false;

  // Execute update
  updateDocuments(coll, filter, doc, options, (err, r) => {
    if (callback == null) return;
    if (err && callback) return callback(err);
    if (r == null) return callback(null, { result: { ok: 1 } });

    r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
    r.upsertedId =
      Array.isArray(r.result.upserted) && r.result.upserted.length > 0
        ? r.result.upserted[0] // FIXME(major): should be `r.result.upserted[0]._id`
        : null;
    r.upsertedCount =
      Array.isArray(r.result.upserted) && r.result.upserted.length ? r.result.upserted.length : 0;
    r.matchedCount =
      Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? 0 : r.result.n;
    r.ops = [doc];
    if (callback) callback(null, r);
  });
}
function replaceOne(coll, filter, doc, options, callback) {
  // Set single document update
  options.multi = false;

  // Execute update
  updateDocuments(coll, filter, doc, options, (err, r) => {
    if (callback == null) return;
    if (err && callback) return callback(err);
    if (r == null) return callback(null, { result: { ok: 1 } });

    r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
    r.upsertedId =
      Array.isArray(r.result.upserted) && r.result.upserted.length > 0
        ? r.result.upserted[0] // FIXME(major): should be `r.result.upserted[0]._id`
        : null;
    r.upsertedCount =
      Array.isArray(r.result.upserted) && r.result.upserted.length ? r.result.upserted.length : 0;
    r.matchedCount =
      Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? 0 : r.result.n;
    r.ops = [doc];
    if (callback) callback(null, r);
  });
}
function replaceOne ( coll , filter , doc , options , callback ) { // Set single document update options . multi = false ; // Execute update updateDocuments ( coll , filter , doc , options , ( err , r ) => { if ( callback == null ) return ; if ( err && callback ) return callback ( err ) ; if ( r == null ) return callback ( null , { result : { ok : 1 } } ) ; r . modifiedCount = r . result . nModified != null ? r . result . nModified : r . result . n ; r . upsertedId = Array . isArray ( r . result . upserted ) && r . result . upserted . length > 0 ? r . result . upserted [ 0 ] // FIXME(major): should be `r.result.upserted[0]._id` : null ; r . upsertedCount = Array . isArray ( r . result . upserted ) && r . result . upserted . length ? r . result . upserted . length : 0 ; r . matchedCount = Array . isArray ( r . result . upserted ) && r . result . upserted . length > 0 ? 0 : r . result . n ; r . ops = [ doc ] ; if ( callback ) callback ( null , r ) ; } ) ; }
Replace a document in the collection.

@method
@param {Collection} a Collection instance.
@param {object} filter The Filter used to select the document to update
@param {object} doc The Document that replaces the matching document
@param {object} [options] Optional settings. See Collection.prototype.replaceOne for a list of options.
@param {Collection~updateWriteOpCallback} [callback] The command result callback
Replace a document in the collection .