rename() - Rename a collection command

Renames a collection.

Syntax diagram

Read syntax diagramSkip visual syntax diagramdb.collection. rename(new_name,forceDrop)

Command parameters

new_name
This parameter specifies a new name for the collection. It must be alphanumeric, with no special characters except for $.
forceDrop(true | false)
If true, this optional parameter drops the existing collection newName.

Example

Rename the books collection to oldbooks:
db.books.rename("oldbooks")
Sample output is as follows:
 Collection Renamed