lib/mongodb/mongodb/lib/operations/collection_ops.js
function rename(coll, newName, options, callback) {
  const Collection = require('../collection');
  // Check the collection name
  checkCollectionName(newName);
  // Build the command
  const renameCollection = `${coll.s.dbName}.${coll.s.name}`;
  const toCollection = `${coll.s.dbName}.${newName}`;
  const dropTarget = typeof options.dropTarget === 'boolean' ? options.dropTarget : false;
  const cmd = { renameCollection: renameCollection, to: toCollection, dropTarget: dropTarget };

  // Decorate command with writeConcern if supported
  applyWriteConcern(cmd, { db: coll.s.db, collection: coll }, options);

  // Execute against admin
  executeDbAdminCommand(coll.s.db.admin().s.db, cmd, options, (err, doc) => {
    if (err) return handleCallback(callback, err, null);
    // We have an error
    if (doc.errmsg) return handleCallback(callback, toError(doc), null);
    try {
      return handleCallback(
        callback,
        null,
        new Collection(
          coll.s.db,
          coll.s.topology,
          coll.s.dbName,
          newName,
          coll.s.pkFactory,
          coll.s.options
        )
      );
    } catch (err) {
      return handleCallback(callback, toError(err), null);
    }
  });
}
function rename(coll, newName, options, callback) {
  const Collection = require('../collection');
  // Check the collection name
  checkCollectionName(newName);
  // Build the command
  const renameCollection = `${coll.s.dbName}.${coll.s.name}`;
  const toCollection = `${coll.s.dbName}.${newName}`;
  const dropTarget = typeof options.dropTarget === 'boolean' ? options.dropTarget : false;
  const cmd = { renameCollection: renameCollection, to: toCollection, dropTarget: dropTarget };

  // Decorate command with writeConcern if supported
  applyWriteConcern(cmd, { db: coll.s.db, collection: coll }, options);

  // Execute against admin
  executeDbAdminCommand(coll.s.db.admin().s.db, cmd, options, (err, doc) => {
    if (err) return handleCallback(callback, err, null);
    // We have an error
    if (doc.errmsg) return handleCallback(callback, toError(doc), null);
    try {
      return handleCallback(
        callback,
        null,
        new Collection(
          coll.s.db,
          coll.s.topology,
          coll.s.dbName,
          newName,
          coll.s.pkFactory,
          coll.s.options
        )
      );
    } catch (err) {
      return handleCallback(callback, toError(err), null);
    }
  });
}
function rename ( coll , newName , options , callback ) { const Collection = require ( '../collection' ) ; // Check the collection name checkCollectionName ( newName ) ; // Build the command const renameCollection = ` ${ coll . s . dbName } ${ coll . s . name } ` ; const toCollection = ` ${ coll . s . dbName } ${ newName } ` ; const dropTarget = typeof options . dropTarget === 'boolean' ? options . dropTarget : false ; const cmd = { renameCollection : renameCollection , to : toCollection , dropTarget : dropTarget } ; // Decorate command with writeConcern if supported applyWriteConcern ( cmd , { db : coll . s . db , collection : coll } , options ) ; // Execute against admin executeDbAdminCommand ( coll . s . db . admin ( ) . s . db , cmd , options , ( err , doc ) => { if ( err ) return handleCallback ( callback , err , null ) ; // We have an error if ( doc . errmsg ) return handleCallback ( callback , toError ( doc ) , null ) ; try { return handleCallback ( callback , null , new Collection ( coll . s . db , coll . s . topology , coll . s . dbName , newName , coll . s . pkFactory , coll . s . options ) ) ; } catch ( err ) { return handleCallback ( callback , toError ( err ) , null ) ; } } ) ; }
Rename the collection.

@method
@param {Collection} a Collection instance.
@param {string} newName New name of of the collection.
@param {object} [options] Optional settings. See Collection.prototype.rename for a list of options.
@param {Collection~collectionResultCallback} [callback] The results callback
Rename the collection .