Use the following command to install MongoDB as a Windows service. The author's MongoDB directory is D:\Program files\mongodb
Switch to D:\Program files\mongodb\bin>
Mongod--logpath "D:\Program files\mongodb\data\logs.txt"--logappend--dbpath "D:\Program files\mongodb\data"-- Directoryperdb--servicename "MongoDB"--servicedisplayname "MongoDB"--install
Enter the above command.
Creating service MongoDB.
Service creation successful.
Service can is started from the command line via ' net start ' MongoDB '.
The command line specifies the log file: D:\Program Files\mongodb\data\logs.tx, the log is exported in an append manner;
Data file directory: D:\Program files\mongodb\data, and the parameter--directoryperdb indicates that each DB will create a new directory;
Name of the Windows service: MongoDB;
Finally, the installation parameters:--install, the opposite is--remove
Start Mongodb:net start MongoDB
Stop Mongodb:net Stop MongoDB
Note: See the log file for problems
MongoDB exception in initandlisten:12596 old lock file, terminating workaround
The error message is as follows:
Exception in initandlisten:12596 old lock file, terminating
Workaround
1. Delete the. lock file in the data directory
2.mongod.exe--repair
3. Start the Mongod and you're ready.
File Source: MongoDB installed as a Windows service
MongoDB installation becomes a Windows service