How do you rename a MongoDB database?
There's a typo in my MongoDB database name and I'm looking to rename the database.
I can copy and delete like so...
db.copyDatabase('old_name', 'new_name');
use old_name
db.dropDatabase();
Is there a command to rename a database? How MongoDB rename database?
For renaming a MongoDB database you can use the following way:-
db.copyDatabase("db_to_rename","db_renamed","localhost")
use db_to_rename
db.dropDatabase();
Or
To Rename a MongoDB Database
Copy the original database by copying all the collections, views, and buckets in it.
Create a new database.
Name the new database as desired.
Paste the copied collections, views, and buckets into the new database.
Drop the original database.