Rename a MongoDB database in two commands

MongoDB has no native rename-database command. The move is mongodump followed by mongorestore into the new name — the old database stays in place until you drop it.

Dump

1mongodump --db old_db --out mongodump/

The dump lands under mongodump/old_db/. Add --uri (or --host/--port/--username/--password) for any non-localhost or auth-protected setup.

Restore under the new name

1mongorestore --db new_db mongodump/old_db/

Or do both in a single pass with namespace mapping (works since MongoDB 4.0), no directory rename needed:

1mongorestore --nsFrom 'old_db.*' --nsTo 'new_db.*' mongodump/

Verify and drop the old database

In mongosh:

1use new_db 2db.getCollectionNames()

Once the collections look right, drop the old database — irreversibly:

1use old_db 2db.dropDatabase()

mongorestore rebuilds indexes and collection options from the dump, but it does not carry users or roles that were bound to the old database name. Re-grant those against new_db separately.