python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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!!


Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions