Sign Up

Sign In

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What is the capital of Egypt? ( Cairo )

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Rename MongoDB Database

Introduction

Renaming a database should be used with extreme caution. Be sure to backup the database first and confirm the new database before removing the old database.

Requirements

  • MongoDB 2.6

Rename with Database Copy

Connect to MongoDB using the mongo shell.

mongo

The old database content can then be copied to a new database.

db.copyDatabase('old_database', 'new_database')

It is recommended that you verify the copy was successful before removing the old database. Once done, the old database can be removed.

use old_database
db.dropDatabase()

Rename with Backup/Restore

The mongodump and mongorestore commands can be used to backup the existing database and then restored into a database with the new name.

mongodump old_database
mongorestore --db new_database ./dump/old_database

The old database can be removed once a successful copy has been confirmed. Connect to MongoDB using the mongo shell.

mongo

The old database can then be removed.

use old_database
db.dropDatabase()

Hits: 1

Leave a comment

What is the capital of Egypt? ( Cairo )