Installing and Running MongoDB Database in Windows 7

What is MongoDB

In this post you will see how to install and running MongoDB database server on Windows 7. What is MongoDB? MongoDB is a NoSQL database. MongoDB is a non-relational JSON document store, a document oriented database. Non-relational means that it does not support the relational algebra that most often expressed in SQL like what RDBMS such as Oracle or MySQL does. The document here is not a Microsoft Word documents or such, but it is a JSON (JavaScript Object Notation) documents.

And if you don’t know what it is look like, here are some examples of JSON documents:

[
  {"firstName" : "John", "lastName" : "Doe", "cityOfBirth" : "New York"},
  {"firstName" : "Julia", "lastName" : "Roberts", "movieTitles" : ["Pretty Woman", "Notting Hill", "Runaway Bride"]}
]

Other characteristics of MongoDB are: it has a dynamic schema, it does not support SQL language, it does not support Joins, and it doesn’t support transactional across multiple collections.

MongoDB Installation

After you know a bit of MongoDB, lets get started with the installation process. Here are the step by step of the MongoDB installation.

  • Download Windows 64-bit MongoDB installer at https://www.mongodb.com/download-center. When this post is written the binary file name for Windows 64-bit is mongodb-win32-x86_64-2008plus-2.6.3-signed.msi.
  • After you have finished download the installer, double-click the file to start the installation wizard.

Welcome to MongoDB Setup

Welcome to MongoDB Setup

  • Press the Next button for the next screen and check I accept the terms in the License Agreement check box and press the Next button to continue.
End-User License Agreement

End-User License Agreement

  • The next step is to choose the setup type. There are three types of setup available, Typical, Custom and Complete. For now, we will choose Complete. So click the Complete button to continue the installation process.
Choose Setup Type

Choose Setup Type

  • Press the Install button to begin installation process.
Ready To Install MongoDB

Ready To Install MongoDB

  • After pressing the Install button, you can see the screen of MongoDB installation process. Wait until the installation is done.
Installing MongoDB

Installing MongoDB

  • And finally you have the MongoDB database installed. Click the Finish button to end the installation process.
Completed MongoDB Installation

Completed MongoDB Installation

The steps above have finalized your MongoDB installation. If you check in your C:\Program Files directory you will see the MongoDB installation directory in there. There will be a bin directory under C:\Program Files\MongoDB 2.6 Standard where all the MongoDB application files. Now you have installed the database server lets run and check the database server.

Running MongoDB

For this step we will focus on two files from the bin directory of the MongoDB installation. The mongod.exe and mongo.exe. The first executable is the MongoDB database engine daemon while the second executable is the shell program to access the MongoDB.

To run the database do the following steps:

  • Create data directory. By default, MongoDB looks for \data\db directory in the root Drive from where you run the mongod. For example, you can create C:\data\db. Or you can use the --dbpath argument to tell MongoDB where to store the data.
  • Open Command Prompt and cd to C:\Program Files\MongoDB 2.6 Standard\bin and type mongod to start the daemon.
Running MongoDB mongod

Running MongoDB mongod

The screen above shows you that the MongoDB is successfully started, using the dbpath \data\db and it is ready and listening for connections on the default port 27017.

Running The Shell

  • Open Command Prompt and cd to C:\Program Files\MongoDB 2.6 Standard\bin.
  • Run mongo.exe to start the shell. You’ll see a welcome message to the MongoDB shell.
Running MongoDB Shell

Running MongoDB Shell

  • In the shell above we run a couple of commands:
  • use peopledb command ask the MongoDB to change to the persons collections, if it doesn’t exist Mongo will create one.
  • To add document to the collections we can call db.persons.insert(); and passing the JSON document as the arguments.
  • To query the collection we can use db.persons.find().
  • If you want for instance to find Julia in the collection you can do db.persons.find({"firstName" : "Julia"})
  • To close the shell we can call quit() command.

That’s all for now, I hope this post is useful for you. In the next post I will show you how to create a simple Java application that use Mongo Java Driver to store data using Java programming into the MongoDB database. So, see you in the next post. Thank you.

Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.