Pages

Thursday, October 10, 2013

Steps to configure MongoDB

Steps to configure MongoDB

Download Mongo
UnZip mongodb-win32-x86_64-2.4.6.zip file in any folder (E:\MongoDB)
Create E:\MongoDB\data\db folder to store database
Open command prompt and run


E:\MongoDB\mongodb\bin\mongod.exe --dbpath E:\MongoDB\data\db\localDB   ==== to set database path

The above command prompt window should remain open so that you can work on database.
Now open another command prompt and run E:\MongoDB\mongodb\bin\mongo   ---- if successfull the below text will appear with a command prompt as ">" here you can execute commands
MongoDB shell version: 2.4.6
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
       
http://docs.mongodb.org/
Questions? Try the support group
       
http://groups.google.com/group/mongodb-user
>Execute your commands here

Download Mongo Interface (Robomongo) http://robomongo.org/ This is a UI tool to execute queries

Folder Structure
All local database localtion E:\MongoDB\data\db\localDB
Backup Folder
E:\MongoDB\dump\localDB\mydb
E:\MongoDB\dump\staging\mongodump-2013-10-10\dbName


BACKUP
mongodump -d <our database name> -o <directory_backup>


Take backup of local database without running the mongod instance
Run on command prompt
E:\MongoDB\mongodb\bin\mongodump --dbpath E:\MongoDB\data\db\localDB -o E:\MongoDB\dump\localDB


Take backup of remote database without running the mongod instance
E:\MongoDB\mongodb\bin\mongodump --host <servername> --port 27017 --username <username> --password <password> -db <dbname> --out E:\MongoDB\dump\staging\mongodump-2013-10-10

RESTORE - From local existing DB
mongorestore <directory_backup>

The mongorestore utility restores a binary backup created by mongodump. By default, mongorestore looks for a database backup in the dump/ directory

Connect to the the mongod instance for local restore
Local
E:\MongoDB\mongodb\bin\mongod.exe --dbpath E:\MongoDB\data\db\localDB   === Instance connection to the database

E:\MongoDB\mongodb\bin\mongorestore E:\MongoDB\dump\localDB  === Run this to restore from backup directory
--Staging
E:\MongoDB\mongodb\bin\mongod.exe --dbpath E:\MongoDB\data\db\localDB   === Instance connection to the database

E:\MongoDB\mongodb\bin\mongorestore E:\MongoDB\dump\staging\mongodump-2013-10-10\dbName === === Run this to restore from backup directory


 

No comments:

Post a Comment