Starting with MongoDB

getting started with mongoDB

I thought of writing this article about mongo DB since starting with mongo DB can be confusing for a beginner and this article provides a short but a comprehensive guide to get things started

What is mongo DB ?

Mongo DB is a leading noSQL database that has gained lot of attention for being

Opensource

Cross platform compatible

Document oriented database written in C++

And for being a part of MEAN stack

Lets see how we can set it up in our machine

Go to https://www.mongodb.com/ and download mongoDB version required according to the Operating system you are working on. Download the msi installer

Follow the steps in the wizard and install it go for the complete installation instead of custom one

Now if u go to C:\Program Files you will find a directory name MongoDB

Go to C:\Program Files\MongoDB\Server\3.4\bin this path may change.all you have to do is find the bin folder inside mongoDB directory and open it .inside it you will see bunch of executable files

executable files inside mongoDB bin folder

Out of these only 2 we will be working now will be mongo and mongod

When u run mongod you can use yourcomputer as a mongo database. mongod will be running in the background

mongo opens up a console/command line interface where you can type and write ur commands and communicate with actual mongo database that is running in the background

open up your command line

navigate to this location C:\Program Files\MongoDB\Server\3.4\bin with cd C:\Program Files\MongoDB\Server\3.4\bin

type mongod and the executable starts running but still there is a small issue that needs to be addressed

before setting data directory, gives a warning to add the data directory

You set up a database but you didn’t tell it where to store the data it is about to receive

So here the mongo DB database is asking u to set up a data directory where it can store all the data it receives and the default location where it looks for a data directory is in local disk C

So navigate to C:\ make a new folder called data in it and inside it make another folder called db

Now the directory is set up

Open up a new commandline and navigate to bin folder and run the executable mongod

DB powers up after adding the data directory

U will get this when you run mongod a second time after setting up the data directory

Now u have a mongo database running in the background

Since navigating to bin file everytime u wanna run the DB is tiring there is a small shortcut we can use

That’s to set up environmental variables- go to environmental variables — add new user variable — use PATH as variable name and add the path C:\Program Files\MongoDB\Server\3.4\bin

This way whenever we type mongo it looks on the location given with PATH, we don’t need to navigate all the time

Now unlike in the previous occasion you can just open up the command line and type mongod without navigating to bin .it will fire up the database

Open up another command line and type mongo in it

This will open up the console where you can write commands to enter ,update ,delete data from the mongo db databse running in the background

I have written a command ‘db’ in it and it shows the default test database available inside the db