In this section we will take a look at installing the MongoDB server and starting it up.
Following are the three steps you need to know or check before you start the MongoDB installation:
The installation of MongoDB is very simple. Once the binaries are downloaded, the server can be up and running in a matter of seconds.
The first step is to visit the site http://www.mongodb.org/downloads to download MongoDB. Always prefer the latest stable build, download the right set of binaries based on your platform. 32 bit version should only be used for development purpose only use 64 bit for production deployments. Since MongoDB uses memory mapped files for data files, the database size is restricted to a total of 2 gigabytes on 32 bit machines. The steps and screenshots I will be giving are for 32 bit Windows platform. For other platforms the steps for installation will remain same.
On Windows you can get the architecture of your platform by typing in the following command into the command prompt:
wmic os get osarchitecture.
Once the binary archive is downloaded and saved to your local disk, we need to extract it. On Windows use any file for archiving. On extracting the archive, go into the bin folder. You should see the content as shown in the following screenshot on a Windows platform. The names of the executables would be same on other platforms. mongo
and mongod
are the only executables we are interested in for now.
Next, we need to start the MongoDB server by executing the mongod
executable from the shell. You may add the bin folder of the extracted folder in your operating system's path
variable. Let's us start by typing in the following command:
> mongod
The server didn't start as we didn't provide the path for the database files on startup. By default the path used is /data/db
and we don't have that folder on our file system. We can either create this directory or provide a custom location for the database.
Let's provide a custom path. Say we use c:MongoDatabase
as our database and try to start the MongoDB server once again. This time around we however provide the --dbpath
parameter. So type in the following command (in your case provide the appropriate path you have chosen for the database) to start the MongoDB server:
> mongod --dbpath C:MongoDatabase
If all goes well, the server now must have started and should be listening for connections on port 27017. This is the default port on which the mongod process listens for new connections.
To stop the server you can press Ctrl + C. This will stop the server in a clean manner.
We should not be too worried about the warning related to journaling. Since we have started the server for development purposes, we do not need journaling. Journaling is a means to ensure that the data files of the database don't go in an inconsistent state even if there is an improper shutdown of the server such as in cases of power failures. In the absence of journaling and unclean shutdown, there are bright chances that your data files will be inconsistent on restart. To know more about journaling, refer to the link http://docs.mongodb.org/manual/administration/journaling/, but don't worry if some of those things don't make much sense for now.
To know all the possible options you can provide while starting the Mongo server, use the --help
option as follows:
> mongod --help
3.137.160.131