В моем случае я создаю mongod.cfg рядом с mongd.exe со следующим содержимым.
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: D:\apps\MongoDB\Server\4.0\data
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: D:\apps\MongoDB\Server\4.0\log\mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
#processManagement:
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
Затем я запускаю обе команды для создания службы.
D:\apps\MongoDB\Server\4.0\bin>mongod --config D:\apps\MongoDB\Server\4.0\bin\mongod.cfg --install
D:\apps\MongoDB\Server\4.0\bin>net stop mongodb
The MongoDB service is stopping.
The MongoDB service was stopped successfully.
D:\apps\MongoDB\Server\4.0\bin>mongod --remove
2019-04-10T09:39:29.305+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-04-10T09:39:29.309+0800 I CONTROL [main] Trying to remove Windows service 'MongoDB'
2019-04-10T09:39:29.310+0800 I CONTROL [main] Service 'MongoDB' removed
D:\apps\MongoDB\Server\4.0\bin>
D:\apps\MongoDB\Server\4.0\bin>sc.exe create MongoDB binPath= "\"D:\apps\MongoDB\Server\4.0\bin\mongod.exe\" --service --config=\"D:\apps\MongoDB\Server\4.0\bin\mongod.cfg\""
[SC] CreateService SUCCESS
D:\apps\MongoDB\Server\4.0\bin>net start mongodb
The MongoDB service is starting..
The MongoDB service was started successfully.
D:\apps\MongoDB\Server\4.0\bin>
Следующие данные не верны, обратите внимание, что экранированные кавычки обязательны.
D:\apps\MongoDB\Server\4.0\bin>sc.exe create MongoDB binPath= "D:\apps\MongoDB\Server\4.0\bin\mongod --config D:\apps\MongoDB\Server\4.0\bin\mongod.cfg"
[SC] CreateService SUCCESS
D:\apps\MongoDB\Server\4.0\bin>net start mongodb
The service is not responding to the control function.
More help is available by typing NET HELPMSG 2186.
D:\apps\MongoDB\Server\4.0\bin>