0 votes
2.3k views
in MongoDB by

How do you rename a MongoDB database ?

1 Answer

0 votes
by

For rename your database you need to follow the following steps:

Step 1. First of all copy all data from old mongodb database (myTestDB) to new mongodb database (myTestDB_Old). Use following command to copy:
> db.copyDatabase("myTestDB", "myTestDB_Old", "localhost")
{ "ok" : 1 }

Step 2. View all created mongodb databases to use following command:
> show dbs
admin    (empty)
myTestDB_Old    0.203125GB
myTestDB    0.203125GB

Step 3. Select working mongodb database to use following command:
> use myTestDB
switched to db myTestDB

Step 4. Then drop working mongodb database to use following command:
> db.dropDatabase();
{ "dropped" : "myTestDB", "ok" : 1 }
 

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...