Install and Configure MongoDB on Windows 8

If you are looking for how to configure mongod as a windows service you can refer this post here.

Most of the time I observed that as a developer we don’t have linux box at our disposal to install softwares and play with them as in contrast ,99 % real world production applications are always being on running on RHEL (Red Hat Enterprise Linux) servers.

In this post we are going to install and configure MongoDB on a windows 8 machine, here I am assuming that you have a basic understanding of MongoDB and how it is different from normal RDBMS. If you don’t have no need to worry you can refer this post to get the basic understanding. So , let’s start

Here, I am going to mention the steps in sequential order.

  1. Download the software from MongoDB official site. Select the Windows 64 bit.
  2. After download you will have a zip file in your local system, extract it and store the contents in location of your choice.
  3. Once you extracted it in your local system you will see a directory structure like this
    C:sauravmongomongodb-win32-x86_64-2008plus-2.4.9bin

    In my case I have saved it in

    C:sauravmongo
  4. Open a command prompt from your windows and make this location your current working directory.
    C:sauravmongomongodb-win32-x86_64-2008plus-2.4.9bin

    Install and Configure MongoDB on Windows 8-1
    Install and Configure MongoDB on Windows 8-1
  5. Now execute the mongod.exe from there . Now when you execute this command you will see an error as mentioned below in the snapshot.
    Install and Configure MongoDB on Windows 8-2
    Install and Configure MongoDB on Windows 8-2

    This is because by default mongo database server looks for default database location (datadb) while starting it, and if it didn’t find this location it will throw an error and will exit the process.
    So, to overcome this error you have to create a directory structure like this somewhere in your local system and pass this location as an argument while starting the mongo database server. You should be happy to know that this is the location where all of your documents and collection objects are going to reside.
    In my case I have defined /data/db location here at the same level in the hierarchy where my mongodb is extracted.

    C:sauravmongodbdata

    Now execute the mongodb command again and pass this location as an argument to it.

    C:sauravmongomongodb-win32-x86_64-2008plus-2.4.9bin>mongod --dbpath C:sauravmongodbdata
    Install and Configure MongoDB on Windows 8-3
    Install and Configure MongoDB on Windows 8-3

    This time you will observe that mongo database server has been started successfully and is running on the port 27017. So , now we are done with the installation and configuration of mongo database server.

  6. By default mongodb comes with javascript shell that can be used to play around with commands that mongo provides to you.This mongo shell client tries to connect to your mongo database server that is running on port 27017 and you have to make sure that before starting the client your mongo database server is up and running otherwise your client will fail to start , as it is not able to connect to mongo server.
  7. Open a new instance of command prompt and make the same location where you have saved mongodb files as your present working directory-
    C:sauravmongomongodb-win32-x86_64-2008plus-2.4.9bin

    Now execute the mongo.exe to start your interactive javascript shell.This time you will see that it connected to the mongo database and by default it is connected to a database with name test.

    C:sauravmongomongodb-win32-x86_64-2008plus-2.4.9bin>mongo.exe

    Install and Configure MongoDB on Windows 8-4
    Install and Configure MongoDB on Windows 8-4
  8. You can also confirm your current database by issuing a db command on the shell.

    Install and Configure MongoDB on Windows 8-5
    Install and Configure MongoDB on Windows 8-5

So , now you have both mongodb server and client running in your system and you can start playing with the different commands that mongo shell provides you.
In the next we will see core components of a mongo db like documents , collections , objects , BSON, etc. Till then stay tuned.

Note : You can add this location C:sauravmongomongodb-win32-x86_64-2008plus-2.4.9bin to your PATH environment variable to avoid setting the present working directory everytime.

 

Let'sConnect

Saurabh Jain

A Developer working on Enterprise applications ,Distributed Systems, Hadoop and BigData.This blog is about my experience working mostly on Java technologies ,NoSQL ,git , maven and Hadoop ecosystem.
Let'sConnect

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

2 thoughts on “Install and Configure MongoDB on Windows 8

Add Comment Register



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>