How to create database in MongoDB?

3 Best Ways to Rename MongoDB Database [Rename]

How do you rename a MongoDB database”? 
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”.

> 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" : ""}
{"_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" : ""}


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”.

> mongodump old_database_name
> mongorestore --db new_database_name ./dump/old_database_name

Reference links,
I hope you are enjoying with this post! Please share with you friends. Thank you!!


Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - and
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book