Using MongoDB under Windows, every time you use it to restart, it's very cumbersome, so how do you start it as a Windows service item? As a system service item is started, it can be used directly after booting.
- Create a new folder under the C drive, C:\Data
- Create a new 2 folder under the Data folder, which you can use to store the information and logs. namely C:\data\db and C:\data\log.
- Copy the path of the Mongod.exe, such as: "C:\Program files\mongodb\server\3.6\bin\mongod.exe", note here, because program Files have spaces in the middle, you must use quotation marks.
- Create a bat file under C:\Data, write: "C:\Program files\mongodb\server\3.6\bin\mongod.exe"--logpath "C:\data\log\mongodb.log" "- -dbpath "C:\data\db"--install--journal
- Run the above script with administrator privileges, you can see the MongoDB Service item in Task Manager, and the service item is in a stopped state. :
- In the Administrator Command Line window, enter net start MongoDB, start the service item (you can also right-click on the MongoDB item in Task Manager and start the service manually):
To start MongoDB as a Windows service item