Search This Blog

Thursday 11 February 2016

Getting started with MongoDB

MongoDB is a NOSQL document database. it doesnt have any RDBMS tables, schema's, relations between tables etc.

read few other from: http://www.tutorialspoint.com/mongodb/mongodb_data_modeling.htm

lets get started with MongoDB setup.
its simple few steps after installing is required.
Here i am writing installation steps for windows

1. Get MongoDB installer from https://www.mongodb.org/downloads#production
2. Install it to your machine, so it will be defaulted to C:\Program Files\MongoDB\
3. To run MongoDB you first need to run mongo.exe from command prompt:
cd C:\Program Files\MongoDB\Server\3.2\bin
mongo.exe

it will give you an error saying "exception in init.....".
Mongo runs as a client-server architecture. so first you need to start mongod.exe - mongo server then the client mongo.exe
Makesure that you have admin privileges

mongod.exe

it will give you another saying listen() bind() failed.
mongo needs a data path to store all the files. So you need to add the datapath in-order to start the server.

create folder named data and give its path.

mongod.exe --dbpath "C:\Program Files\MongoDB\Server\3.2\bin\data"


now server will be waiting for connections. so now you can start your mongo client.

mongo.exe from another cmd prompt.
you will see a cmd prompt this way
>

which means you are connected to mongo.
now note the following basic commands of mongo:
db - shows current database
show dbs - lists all databases

run these two to make sure you are connected to mongo.
this is cool. but every time running two two exe's is boring.
so, keep mongod as windows service so that it will run in background everytime.

mongod.exe --dbpath "C:\Program Files\MongoDB\Server\3.2\bin\data" --logpath "C:\Program Files\MongoDB\Server\3.2\bin\data\log.txt" --install

this install mongod -mongo daemon as service. but it wont start mongod service.
to do that use
net start MongoDB

mongo.exe


to make it little more easier, add C:\Program Files\MongoDB\Server\3.2\bin to PATH environment variable so that you need not traverse to program files every time.

Reference:
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/

No comments:

Post a Comment