MongoDB installation for Windows service methods and considerations

Source: Internet
Author: User
Tags install mongodb

The source of this article: http://blog.csdn.net/chaijunkun/article/details/7227967, reprint please specify. Because I do not regularly collate the relevant blog posts, the corresponding content will be improved. It is therefore highly recommended to view this article in the original source.


MongoDB, a database based on distributed file storage, has been in great pursuit for nearly two years. The flexible access and efficient processing of data makes it widely used in Internet applications.

Recently I began to study the use of MongoDB under the Windows 32-bit platform, I prefer to install it as a system service for Windows for convenience. This will not have to open a Mongod mainstream program every time.

However, the command to search the Internet does not allow the service to register successfully, and there are some problems. Next I will write out the problems and solutions I have encountered.


First download the latest release version from MongoDB official: http://www.mongodb.org/downloads

I am currently using the 2.0.2 version.

Installation is very simple, decompression out on it. I put it under the D-Disk, the following is the directory structure:

c:\documents and SETTINGS\CHAIJUNKUN>D:D:\>CD The volume in MONGODB-WIN32-I386-2.0.2D:\MONGODB-WIN32-I386-2.0.2>CD bind:\mongodb-win32-i386-2.0.2\bin>dir drive D is not labeled. The serial number of the volume is the directory of f4ca-b47c D:\mongodb-win32-i386-2.0.2\bin 2012-02-01 16:48 <DIR>. 2012-02-01 16:48 <di R>. 2011-12-14 12:23 3,644,928 bsondump.exe2011-12-14 12:25 1,793,536 mongo.exe2011-12-14 12:28 3,9 52,640 mongod.exe2011-12-14 3,660,800 mongodump.exe2011-12-14 12:32 3,651,072 mongoexport.exe2011-         12-14 12:34 3,656,192 mongofiles.exe2011-12-14 12:36 3,668,992 mongoimport.exe2011-12-14 12:38 3,654,656 mongorestore.exe2011-12-14 12:39 2,807,808 mongos.exe2011-12-14 12:41 3,689,472 mongostat.exe2 011-12-14 12:46 3,657,216 mongotop.exe 11 files 37,837,312 bytes 2 directories 97,404,313,600 available In bytes 



The next step is to install MongoDB service, but at this point pay attention to two points:

1. Keep the command line current directory unchanged, that is, still stay in the D:\mongodb-win32-i386-2.0.2\bin directory. Using absolute positioning to manipulate this directory after any changes to another directory will cause the service installation to fail

Note: What does that mean? That means keeping the current state on the line. If you reopen a cmd, the starting directory becomes

C:\Documents and Settings\chaijunkun>



When you use
C:\Documents and Settings\chaijunkun>d:\mongodb-win32-i386-2.0.2\bin\mongod.exe .......



Such a way to register the service will still fail to register.


2. Create a directory in advance to save the database file. If you do not create this directory, registering the service appears to have registered successfully. However, starting the service will find that the Mongod.exe process will be repeatedly created, destroyed, built, destroyed. Then the service status becomes "Started", "Stopped", "started", "Stopped", and the client cannot connect to the database at all.

Here I use the Mongodbdata directory under the C drive as the data file directory, and then set up the directory:

D:\mongodb-win32-i386-2.0.2\bin>mkdir C:\MongoDBData




Well, get ready for work here, you can install the service below:
D:\mongodb-win32-i386-2.0.2\bin>mongod--install--servicename MongoDB--servicedisplayname mongodb--logpath c \ MongoDB.Log--dbpath C:\MongoDB--directoryperdb



Here is a brief introduction to the parameters used and their meanings:

--install: Installing MongoDB Service

--servicename: Service name to use when installing Windows services

--servicedisplayname: The name of the service that is displayed in Windows Service Manager, as follows:

--logpath:mongodb the log output file name. Although this parameter literal is "log path", in fact, you want to specify a specific full file name. Here I am using the MongoDB.Log file under the C packing directory. The file is not created in advance and is specified directly.

--dbpath: Specifies the path where the MongoDB data is stored. This is the most important parameter, not only the directory to exist, and it is best not to end with "\".

--DIRECTORYPERDB: This parameter is very well understood, let MongoDB according to the database different, for each database to establish a directory, so-called "directory per database"


Well, after executing the above command, the service will be able to register successfully. If you are using Windows Vista or Windows 7, you have to pay special attention to its UAC mechanism, you must open cmd with administrator privileges, and then register the service to successfully register.

Open the Service Manager, start the MongoDB service, and discover that the service can run stably and continuously. Congratulations, you've done it!

MongoDB installation for Windows service methods and considerations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.