lib/operations/collection_ops.js
function findOneAndReplace(coll, filter, replacement, options, callback) {
  // Final options
  const finalOptions = Object.assign({}, options);
  finalOptions.fields = options.projection;
  finalOptions.update = true;
  finalOptions.new = options.returnOriginal !== void 0 ? !options.returnOriginal : false;
  finalOptions.upsert = options.upsert !== void 0 ? !!options.upsert : false;

  // Execute findAndModify
  findAndModify(coll, filter, options.sort, replacement, finalOptions, callback);
}
function findOneAndReplace(coll, filter, replacement, options, callback) {
  // Final options
  const finalOptions = Object.assign({}, options);
  finalOptions.fields = options.projection;
  finalOptions.update = true;
  finalOptions.new = options.returnOriginal !== void 0 ? !options.returnOriginal : false;
  finalOptions.upsert = options.upsert !== void 0 ? !!options.upsert : false;

  // Execute findAndModify
  findAndModify(coll, filter, options.sort, replacement, finalOptions, callback);
}
function findOneAndReplace ( coll , filter , replacement , options , callback ) { // Final options const finalOptions = Object . assign ( { } , options ) ; finalOptions . fields = options . projection ; finalOptions . update = true ; finalOptions . new = options . returnOriginal !== void 0 ? ! options . returnOriginal : false ; finalOptions . upsert = options . upsert !== void 0 ? ! ! options . upsert : false ; // Execute findAndModify findAndModify ( coll , filter , options . sort , replacement , finalOptions , callback ) ; }
Find a document and replace it in one atomic operation. This requires a write lock for the duration of the operation.

@method
@param {Collection} a Collection instance.
@param {object} filter Document selection filter.
@param {object} replacement Document replacing the matching document.
@param {object} [options] Optional settings. See Collection.prototype.findOneAndReplace for a list of options.
@param {Collection~findAndModifyCallback} [callback] The collection result callback
Find a document and replace it in one atomic operation . This requires a write lock for the duration of the operation .