How to rename a MongoDB database

1127730 pts.
Tags:
Database
MongoDB
I just realized there's a typo in my MongoDB database name and I need to change the name ASAP. I've tried to copy and delete it like this:
db.copyDatabase('old_name', 'new_name');
use old_name
db.dropDatabase();
Would there be a command to rename it?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi

You
will easily rename it with the help of given command:

db.copyDatabase(“db_to_rename”,”db_renamed”,”localhost”)

use db_to_rename

db.dropDatabase();

For more info see this: http://docs.mongodb.org/manual/tutorial/backup-with-mongodump/

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • erickveras
    The command copyDatabase is deprecated. now needs use mongodump e mongorestore
    https://docs.mongodb.com/manual/release-notes/4.0-compatibility/#copydb-and-clone-commands
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: