How To Install MongoDB On Windows

MongoDB, is an open source document database and the leading NO SQL database written in C++. MongoDB is used as a persistence store and it get adapted by different latest libraries and implementations, so Eclipse JPA/NoSQL has provided a library for get your application integrated with MongoDB as Spring Data. In this tutorial, we are going to install and configure the MonogoDB step-by-step.

Download MongoDB Installation File

To download the proper installation file for your operating system you have to follow the following link. For this tutorial we are going to install the MongoDB for Windows.
MongoDB Required Installation File Windows

Install MongoDB

After downloading the required file, you have to install it on your operating system, by double clicking on the installed file, it will start the installation process. Follow the below steps for finishing the installation process.
MongoDB Installation First Step
  • By pass the welcome screen by clicking on the next.
MongoDB Installation Second Step
  • Accept the terms in the License Agreement
MongoDB Installation Third Step
  • Use a Custom installation for more controlling upon where is the location of the installation and what’s the component that are being installed.
MongoDB Installation Forth Step
  • By clicking Browse, you have to change the location of the installation.
  • By expanding the root feature tree, you can select/deselect the required/un-required features.
MongoDB Installation Change Installation Path
  • The preferred location for installing MongoDB, is to install it using a path with no spaces. The suggested path for this guide is C:\mongodb\.
MongoDB enable all features
  • Enable all features.
Pre Install
  • Click install to begin the installation process
Installing Process
  • The installation in progress.
Installation has finished
  • MongoDB Installation is completed, If you see the above screen.

MongoDB Configurations

MongoDB isn’t traditional database, so you are not about using or dealing with Schemas and Database Tables, but you are about document based data store. The concept of document based isn’t like the well-known document that every one could use it, rather it’s JSON document, and it needs a location for being saved. For that purpose, you shall configure that location the documents are saved within it. Such a configuration is what you will be seeing by following the below steps:
  • Go into your installation directory and based on our tutorial, it’s C:\mongodb.
  • Create a folder for being considered as a repository location. For that you can create C:\mongodb\data\db.
  • That path should be passed through starting up the MongoDB instance.
Create Data Folder
  • This is the form of the directories after created the data location.
Data location After Starting Up MongoDB
  • MongoDB has used the created directory for bootstrapping and initializing the required data.

Starting Up and Connecting MongoDB

Once you are installing the configuring the MongoDB you are ready for starting it up and making it ready for use. Execute the following commands for a proper initialization of MongoDB.
  • Go into the installation directory, and based on our tutorial, it’s C:\mongodb.
  • Navigate into \bin.
  • Execute the mongodb.exe –dbpath=”C:\mongodb\data\bin” for passing the desired saving location that the MongoDB has to use for storing the supposed document that persisted by the client. Client here, is whatever application that want to connect the MongoDB, so it could be a user that connected MongoDB through the command line, or it could be an application that using the required library for connecting the MongoDB.
  • The successful execution for the above command, should configure the mongodb and it should also starting it up and it is  ready for use.
Starting MongoDB
  • Starting Up the MongoDB has by turn initialized the MongoDB and locating the passed location for the next coming further operations.

Connecting MongoDB

For connecting MongoDB, you have multiple choices:
  • Connecting MongoDB using the command line by navigating into C:\mongodb\bin and executing mongo.exe.
  • If you’ve not provided any name after mongo.exe, you are almost connecting the default database test.
  • If you’ve provided a name, the mongodb itself will try to locate that name as a database name, if it didn’t find that database, it will create it automatically.
  • MongoDB will create & open the database that you’ve passed through mongo.exe. In the below screenshot, we are creating a database called “JavaBeat”.
Connecting Database
  • By connecting MongoDB, you have the ability to operate and acting on the connected database.

Sample Find Operation in MongoDB

The below snapshot shows you a sample example of executing find operation upon USER collections (Collection is an alternative concept of Table).
Find operation

Commentaires