Renaming a database should be used with extreme caution. Be sure to backup the database first and confirm the new database before removing the old database.
- MongoDB 2.6
Rename with Database Copy
Connect to MongoDB using the mongo shell.
The old database content can then be copied to a new database.
It is recommended that you verify the copy was successful before removing the old database. Once done, the old database can be removed.
Rename with Backup/Restore
The mongodump and mongorestore commands can be used to backup the existing database and then restored into a database with the new name.
mongorestore --db new_database ./dump/old_database
The old database can be removed once a successful copy has been confirmed. Connect to MongoDB using the mongo shell.
The old database can then be removed.