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\', \
From version 4.2, the copyDatabase is deprecated. From now on we should use: mongodump and mongorestore.
Let's say we have a database named: old_name and we want to rename it to new_name.
First we have to dump the database:
mongodump --archive="old_name_dump.db" --db=old_name
If you have to authenticate as a user then use:
mongodump -u username --authenticationDatabase admin \
--archive="old_name_dump.db" --db=old_name
Now we have our db dumped as a file named: old_name_dump.db.
To restore with a new name:
mongorestore --archive="old_name_dump.db" --nsFrom="old_name.*" --nsTo="new_name.*"
Again, if you need to be authenticated add this parameters to the command:
-u username --authenticationDatabase admin
Reference: https://docs.mongodb.com/manual/release-notes/4.2-compatibility/#remove-support-for-the-copydb-and-clone-commands