“How do you rename a MongoDB database”?
“How to Backup and Restore MongoDB using mongodump and mongorestore”?
“How to Backup and Restore MongoDB using mongodump and mongorestore”?
“3 Ways” to Rename MongoDB Database as,
1. Rename with Database copy.
2. Rename with Backup/Restore.
3. Backup by Shutting down Mongod Instance.
We are using “mongodump” and “mongorestore” commands to Backup and Restore to MongoDB.
Rename with Database Copy:-
In this method, connect to MongoDB with “mongo shell”.
Examples,
> show dbs admin 0.000GB local 0.000GB mydb 0.000GB > db.copyDatabase("mydb","myNewDB","localhost") { "ok" : 1 } > use mydb switched to db mydb > db.dropDatabase() { "dropped" : "mydb", "ok" : 1 } > show dbs admin 0.000GB local 0.000GB myNewDB 0.000GB > use myNewDB switched to db myNewDB > db.users.find() {"_id" : ObjectId("584f9fca071fb26c09aeb191"), "name" : "Anil Sngh", "site" : "code-sample.com"} {"_id" : ObjectId("584fb58ea529193a8cc59605"), "name" : "Alok", "site" : "code-view" } {"_id" : ObjectId("584fb9c5a529193ff41743fd"), "name" : "Alok", "site" : "code-view", "CretaeDate" : ISODate("2016-12-13T09:05:09.627Z") } {"_id" : ObjectId("585230478c92c30dfd10bed0"), "name" : "Reena", "site" : "www.code-sample.xyz"} >
Rename with Backup/Restore:-
In this method, the mongodump and mongorestore command will be used to back-up the “old database” and then “restored” into a “new database”.
Examples,
> mongodump old_database_name > mongorestore --db new_database_name ./dump/old_database_name
Reference links,
· http://mongodb.github.io/node-mongodb-native/2.2/quick-start/?_ga=1.260262281.524125354.1481516570