MongoDB tutorial – part 1

Mongo DB is document based data based. Document is just self-contained chunk of information. We can  group many documents into collection and many collections into DB.
So in Mongo database is a set of collection, and a collection is a set of documents. One great advantage of document database is mapping of the program objects into the database entities, it is easier.

 

In order to install mongoDB, got to their download page and follow their instruction.
In order to start the server we can run the following. <dataLocation> is the directory that we want to contain the mongoDb data


mongod --dbpath=<dataLocation>

From the location of the mongod, or if the mongo binary in the path.
mongo server run on port 27017.

Mongo database store the information in binary JSON format called BSON.
BSON format has some features like:

  1. length prefix for every field – that help to save time when doing i/o to the disk, if we don’t need the field, then when know to where more the file pointer.
  2. support additional primitive that are not supported in JSON like UTC Date. Also the type of every field is stored with the field.

In order to start mongo REPL, we need to run mongo client, we cam do this by running:


mongo
2016-10-26T20:11:06.574+0300 I CONTROL [main] Hotfix KB2731284 or later update is installed, no need to zero-out data files
MongoDB shell version: 3.2.10
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
> 

Once we start the mongo client, we get the REPL (read, evaluate, print, loop) and we can start running commands.
The first command that we run is db, this command will tell us the out current used db.
The second command is use <dataBaseName>  will switch to the database dataBaseName.

In the below example we will run db, to check the database and then change the database to check.


C:\Program Files\MongoDB\Server\3.2\bin>mongo
2016-10-26T20:21:49.955+0300 I CONTROL  [main] Hotfix KB2731284 or later update is installed, no need to zero-out data files
MongoDB shell version: 3.2.10
connecting to: test
> db;
test
> use check;
switched to db check
> db
check
>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s