Tuesday, September 2, 2014

Start with MongoDB - A new experience with NoSQL database

I will not discuss about what MongoDB is?
MongoDB official website itself provides all the information what you need. Also, there is a lot of information available on Internet when you search Why there is a need of NoSQL database?
Below are the steps to start with MongoDB in Windows:
1. Download the appropriate version from Download page.
2. Double click on installer and follow the installation wizard.
By default, you will not see any service named as MongoDB in Services window.
You have to create a configuration file, log file and data directory and mention the path of log file and datapath in the configuration file.
3. Locate the path of installed MongoDB in your system.
4. MongoDB is not restricted with any specific path for data directory or log path. It depends upon you what path you assigned in configuration file.
For example, MongoDB has been installed in C:\Program Files\MongoDB 2.6 Standard\
Important note: if directory name contains space then we must put the path within double quote.
5. Open the Command Prompt as administrator. (Right click on the CMD link and select "Run as administrator").
6.  Create data directory. 
C:\Program Files\MongoDB 2.6 Standard\bin>md data
C:\Program Files\MongoDB 2.6 Standard\bin>cd data
C:\Program Files\MongoDB 2.6 Standard\bin\data>md db
C:\Program Files\MongoDB 2.6 Standard\bin\data>cd..
C:\Program Files\MongoDB 2.6 Standard\bin>cd..
7. Create log path
C:\Program Files\MongoDB 2.6 Standard>md log
C:\Program Files\MongoDB 2.6 Standard>cd log
C:\Program Files\MongoDB 2.6 Standard\log>type NUL > mongo.log
C:\Program Files\MongoDB 2.6 Standard\log>cd..
8. Create configuration file
C:\Program Files\MongoDB 2.6 Standard>echo logpath="C:\Program Files\MongoDB 2.6
 Standard\log\mongo.log" > "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"
Concatenate below line in your configuration file:-
dbpath="C:\Program Files\MongoDB 2.6 Standard\bin\data\db"
9. Start MongoDB server
C:\Program Files\MongoDB 2.6 Standard>"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe" --dbpath="C:\Program Files\MongoDB 2.6 Standard\bin\data\db"
MongoDB server will be started and you will see that MongoDB server is waiting for connections. Please do not close this window.
10. Open MongoDB shell 
Open another Command prompt with  administrator privileges.
C:\Program Files\MongoDB 2.6 Standard\bin>mongo.exe
Shell prompt will display where you can execute MongoDB commands and statements just like this one.

If you want to avoid to start MongoDB server each time, you can install this as a service too.
11. Install MongoDB sevice in windows system:
C:\Program Files\MongoDB 2.6 Standard>"C:\Program Files\MongoDB 2.6 Standard\bin
\mongod.exe" --config "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg" --dbpat
h "C:\Program Files\MongoDB 2.6 Standard\bin\data\db" --logpath "C:\Program File
s\MongoDB 2.6 Standard\log\mongo.log"  --install

12. Start MongoDB service:
You will see that MongoDB is also listed in your services window ( Windws button+R -> type services.msc). From here , you can click on start.
Alternatively, you can issue below line from command line:
C:\>net start MongoDB
You will see the MongDB shell.

13. Stop MongoDB service:
First execute exit command in MongoDB shell.
C:\>net stop MongoDB

14. Uninstall MongoDB sevice:
C:\Program Files\MongoDB 2.6 Standard>"C:\Program Files\MongoDB 2.6 Standard\bin
\mongod.exe" --remove

To proceed with DB operations like creating database, select database and other operations, please visit MongoDB official tutorial.













Important queries based formulas to watch performance of a MySQL based application

(1) Session Vs global status variables value select G.variable_name,G.variable_value GlobalValue,S.variable_value SessionValue from (selec...