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 MonogDB 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.
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.
- By pass the welcome screen by clicking on the next.
- Accept the terms in the License Agreement
- Use a†Custom†installation for more controlling upon where is the location of the installation and what’s the component that are being installed.
- 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.
- 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\.
- Enable all features.
- Click install to begin the installation process
- The installation in progress.
- MongoDB Installation is completed, If you see the above screen.
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.
- This is the form of the directories after created the data location.
- 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 Up the MongoDB has by turn initialized the†MongoDB†and locating the passed location for the next coming further operations.
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”.
- 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).