Try Studio 3T for Free
  1. Knowledge Base
  2. Query & CRUD Operations
  3. How to Rename a MongoDB Database – A Quick 5-Step Workaround

How to Rename a MongoDB Database – A Quick 5-Step Workaround

The ability to rename a MongoDB database is a feature that the MongoDB team is still working on.

In the meantime, there’s an easy workaround that only requires a few clicks when using the MongoDB GUI, Studio 3T:

  1. Copy the original database by copying all the collections, views, and buckets in it.
  2. Create a new database.
  3. Name the new database as desired.
  4. Paste the copied collections, views, and buckets into the new database.
  5. Drop the original database.

Let’s rename the database users to customers as an example.

Start your free 30-day Studio 3T trial to follow along. 

Step 1: Copy the original MongoDB database

Once you’ve connected to a MongoDB instance, you’ll see the list of databases in the Connection Tree on the left-hand side:

Find your database in the Connection Tree on the left-hand

Studio 3T’s rich context menus conveniently replace needing to run basic MongoDB CRUD commands in the shell.

In this case, all we need to do copy the contents of the users database is:

  1. Right-click on the users database.
  2. Click on Copy All Collections/Views/Buckets.

Right-click on the database and choose Copy All Collections

If you don’t see copy options, please ensure that you have not selected more than one node (e.g. two databases, a database and a collection inside). 

Step 2: Create a new MongoDB database

Next, we’ll create a new database where we can paste the copied content.

To add a database:

  1. Right-click on the target server (which is Studio 3T Replica Set in our example).
  2. Choose Add Database

Right-click on the server to add a MongoDB database

Step 3: Name the new database

The Add Database dialog will pop up.

Here, we can name the newly-created database customers and click OK.

Name the newly created MongoDB database as you wish

The database called customers should then appear in the Connection Tree.

Step 4: Paste the contents of the original database

Now that we’ve created the new database, we’ll then paste the contents of the original database users into customers.

  1. Right-click on the customers database.
  2. Choose Paste Collections/Views/Buckets.

Paste the contents of the old database into the new database


How long this process takes will depend on how large your original database is. You can always track the progress in the Operations window, below the Connection Tree on the bottom-left hand side.

Track your job's progress in the Operations window

Step 5: Drop the original MongoDB database

After making sure that everything has been correctly copied into the new database, we can drop the original database, users.

Note that you need to have the appropriate user rights to do so, otherwise Studio 3T will throw off an error message.

  1. Right-click on the original database.
  2. Choose Drop database.
  3. Click Drop database.

Drop the original MongoDB database

The original database should then disappear from the Connection Tree.

Updated on October 23, 2020

Was this article helpful?

Related Articles

Leave a Comment