Configuring MongoDB Services

Source: Internet
Author: User
Tags create mongodb

The previous section talked about the environment of MongoDB, but the way to start MongoDB is too cumbersome.

Let's talk about it today. Simplifies the configuration of MongoDB startup.

The "C:\Program files\mongodb 2.6 standard\bin\mongod.exe" command, which is run at the command line first, can be simplified to a direct mongod command by putting C:\Program files\ MongoDB 2.6 standard\bin Path is added to the PATH environment variable

For simplicity, you can define "C:\Program Files\mongodb 2.6 standard" as a system variable mongo_home,

The variable is then referenced in path

  

Once defined, you can run the mongod,MONGO commands directly at the command line , note: When configured, close the command-line window and open it. and run as administrator to take effect .

It's too hard to add a data storage path every time you start a mongoDB database.

C:\Program FILES\MONGODB 2.6 Standard\bin\mongod.exe--DBPath D:\mongodb\data\data

We can add a configuration file to MongoDB so that it will load the configuration file by default when it starts.

I want to put the configuration file and MongoDB 's installation directory together, in the mongo_home directory, but this is not allowed to create their own files, unless there is administrator rights.

Configure the log options first

We will first create the following log file in the Data directory:

D:\mongodb\data\log\mongo.log

Then add the log directory LogPath to the configuration file ( the path must not be written wrong,logpath The path behind the quotation marks, or start the service prompt "The service does not respond to control functions. ")

echo logpath=d:\mongodb\data\log\mongo.log > "%mongo_home%\mongod.cfg"

The configuration files are generated in the MongoDB installation root directory and configured logpath

Create a configuration file and configureDBPath

Append the Data directory DBPath to the configuration file ( the path must not be written wrong,dbpath The path behind the quotation marks, or start the service prompt " The service does not respond to control functions. ")

echo dbpath=d:\mongodb\data >> "%mongo_home%\mongod.cfg"

The configuration file opens at this time

  

Now that the configuration file has been generated, how do you let MongoDB know the location of the configuration file?

You can run the following command to install the mongoDB service According to the configuration file:

Sc.exe create MongoDB binpath= "\" C:\Program files\mongodb 2.6 standard\bin\mongod.exe\ "--service--config=\" c \ Program Files\mongodb 2.6 standard\mongod.cfg\ "" displayname= "MongoDB 2.6 standard" start= "Auto"

  

Service installation Succeeded

Let's go to "this computer--and manage --services and apps -- services" to see if the service exists

  

The service does already exist.

Next start the MongoDB Service:

net start MongoDB

  

To stop the MongoDB Service, you can run the following command:

net stop MongoDB

To uninstall the MongoDB Service, you can run the following command:

Delete Mongodb
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.