DEV Community

Andreas Bergström
Andreas Bergström

Posted on • Edited on • Originally published at andreasbergstrom.dev

Rename a MongoDB database in two commands

MongoDB has no built-in rename for databases — but mongodump and mongorestore get you there in two commands. Dump the old database to disk with mongodump -d old_db_name -o mongodump/, then restore it under the new name with mongorestore -d new_db_name mongodump/old_db_name. Verify the collections from the shell, drop the old database when you're satisfied, and you're done.

The full post walks through each step with the exact commands, plus the verification check that catches a half-restored copy before you drop the original.


Originally published at andreasbergstrom.dev — read the full post there.

Top comments (0)