如何设置MongoDB,使其可以作为Windows服务运行?


当前回答

check windows services if you have service for mongo remove it by run bellow command mongod --remove create mongo.cfg file with bellow content systemLog: destination: file path: c:\data\log\mongod.log storage: dbPath: c:\data\db path: where you want to store log datas dbPath: your database directory then run bellow command sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\3.2\mongod.cfg\"" DisplayName= "MongoDB" start= "auto" binPath : mongodb installation directory config: .cfg file address DisplayName:Your Service Name start service net start MongoDB

现在一切都办好了。享受,

其他回答

mongod --config "C:\Program Files\MongoDB\Server\3.6\mongod_primary.cfg" --install --serviceName "MongoDB_Primary" --serviceDisplayName "MongoDB Primary"

这是唯一对我有用的方法。因为所有东西都必须是绝对路径:

C:\Program Files\MongoDB\Server\3.2\bin>mongod --install --dbpath=c:/data/db --logpath=c:/data/logs/log.txt

我还必须从管理cmd运行它

在Windows系统上编辑配置文件后,我不得不重新启动MongoDB (v4.4)服务。以下是我所做的:

按Win+R打开Run面板 输入“服务”。msc”,按“Enter” 搜索“MongoDB”-你可以按“m”跳转到它。 右键单击-选择“重新启动”

就是这样!

不仅——安装,

还需要——dbpath和——logpath

重启操作系统后,你需要删除“mongod”。手动锁”

这对我来说很管用:

sc.exe create MongoDB binPath= "d:\MongoDB\bin\mongod.exe --service --config=d:\MongoDB\bin\mongod.config" displayname= "MongoDB 2.6 Standard" start= "auto"

逃脱binPath是失败的我在Mongo文档中描述

失败:

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"