Install, Set Up and Start MongoDB on Windows
This post will provide the full path from downloading the required binary archive/package for particular a Windows version to starting up MongoDB in various ways
We will go through the following high level steps-
- Download the MongoDB binary archive for windows platform
- Extract MongoDB archive
- Setup up configuration parameters and start/stop MongoDB
- using command line
- using windows services
For Windows platform, MongoDB distributes zip archive. Go to following downloads page from browser http://www.mongodb.org/downloads
Depends on system architecture, it comes in two distribution as
Downloading the 64-bit is recommended. Again, MongoDB distribution for Windows 64-bit ships with two flavors
- one for Newer OS, Windows server 2008 and Windows 7, Server 2012 (download link Big Green button)
- other for Older OS, Windows Server 2003,2008 and Vista (Download link, 64-bit legacy )
This distinction for x64 is made based on newer OS features which helps in enhanced performance of MongoDB.
Choose the production releases for downloading as shown in following image
After you download, you will get zip archive in follwing format-
mongodb-<platform>-<architecture>-<version>.zipExtract MongoDB archive
Once we have MongoDB archive, go ahead and extract archive using any zip extract program.
After extracting, you will get the directories inside archive as follows
here , bin directory contains the binaries in form of executables , such as mongod.exe, mongo.exe, monogexport.exe etc.Setup up configuration parameters and start/stop MongoDB
For starting and stopping the MongoDB server, we need only the bin/mongod.exe, which is the daemon process executable for MongoDB. In short, it is the executable which starts up the MongoDB Server.
For starting up, we need to provide the parameters for executable, which i call it here as config parameters or params.
We can setup the config parameters using the two ways
- Using command line options or
- Using config file
Using command line options
With use of these command line options, we configure mongo daemon process. Basically, there lots of options we can specify but i will give only those which required for this tutorial.
Following are someof them-
–dbpath <path> : the existent directory path, which is required to store data files. this is most important option we need to specify, Note that, the directory path you are providing should exists otherwise process won’t start. If this path contains spaces then put all its path in double qoutes. e.g. –dbpath “c:\Program Files”
–logpath <log-file-path>: the existent file path, used by mongo daemon process,for flush out loggs instead of in standard console. If this path contains spaces then put all its path in double qoutes
–port <port> : port no. where mongod process listen for connection from client, it defaults to 27017 if not specified
Note : While using the command prompt on some Windows OS like windows 7 or Windows server 2008, Run it with administrator privileges as shown as follows
Use the following commands to start the server process
Change to bin directory
shell> I:\>cd Servers\mongodb\bin
now type following command to start the mongod process
shell > mongod --dbpath I:\Servers\data --port 27017
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)