Tuesday, May 11, 2010

Installing MongoDB on a Windows Server

To start, I downloaded the latest mongo binaries from  the mongo download site.  This was version 1.4.2 at the time of this writing.  I was installing mongo on a 64 bit Windows 2008 server so I picked the Windows 64-bit binary package.

On the server, I created the folder C:\Program Files\MongoDB to hold the binaries and the folder C:\ProgramData\mongodb\data to hold the mongo databases.  I then extracted the binaries from the downloaded file (mongodb-win32-x86_64-1.4.2.zip) to the C:\Program Files\MongoDB folder.  I then opened a command prompt as Administrator and installed mongo as a service by executing the following line:

“C:\Program Files\MongoDB\bin\mongod” -–dbpath C:\ProgramData\mongodb\data -–install

This runs the mongod.exe executable and tells it to use C:\ProgramData\mongodb\data as its database directory and to install itself as a Windows service.  It is important that you use the full path to the mongod.exe executable or else the Windows service control manager will not be able to find the executable to start the service.  The service can now be started by executing the this command from the administrative command prompt:

net start MongoDB

I then used the mongo.exe database client application to test the install.  I inserted a simple person record and then queried for that record.  Mongo creates a ‘test’ database and a ‘things’ collection on my behalf and inserts the document into it.  A screen shot is shown below.  You can see the object ID assigned to the document by mongoDB.

mongo-1

 

To access mongoDB from another computer the Windows firewall needs to be configured.  I allowed any domain connections to access this installation of mongo.  This may not be acceptable for your needs.  As this is a test database in my environment, this configuration is acceptable.  Here is a screen shot to show the configuration in Windows firewall.

mongo-2

 

Now I wanted to connect to the database from another computer.  On my own desktop I then ran the mongo.exe database client to connect to the server and the ‘test’ database.  Then I queried for the known record.  The results are shown below.

mongo-3

As you can see you use the <server name>/<database name> pair to connect.  There are many more options of course, but this is sufficient if you are using the defaults. 

No comments:

Post a Comment