[MongoDB] How to rename/change database names

Tadashi Shigeoka ·  Tue, August 2, 2016

I’ll introduce the procedure for changing database names in MongoDB.

MongoDB | モンゴディービー

Prerequisites

First, MongoDB doesn’t have a way to atomically rename DB names, so the procedure is to copy and then delete the old DB.

DB name change procedure

Here are the MongoDB commands to change database names:

// Copy the database with the new name you want to change to
db.copyDatabase('old_name', 'new_name');
// Switch to the old database
use old_name
// Delete the old database
db.dropDatabase();

If the database is large, db.copyDatabase will take time, but there’s no choice but to wait patiently.

That’s all from the Gemba.