Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in SQL by (47.6k points)

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?

2 Answers

0 votes
by (106k points)

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();

0 votes
by (107k points)

You could do this:

db.copyDatabase("db_to_rename","db_renamed","localhost")

use db_to_rename

db.dropDatabase();

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...