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


当前回答

我发现你应该用install标志将:dbpath, config和logfile传递给mongod

例子:

mongod --dbpath=c:\data\db --config=c:\data\db\config.cfg --logpath=c:\data\db\log.txt --install 

注意:我的路径变量中有mongod path。

你可以通过以下方式控制服务:

net start mongodb
net stop  mongodb 

其他回答

不仅——安装,

还需要——dbpath和——logpath

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

以管理员身份运行“cmd.exe”,然后运行“sc.exe”,添加一个新的Windows服务。

例如:

sc.exe create MongoDB binPath= "c:\program files\mongodb\server\3.2\bin\mongod.exe"

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

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

以下步骤适用于Windows操作系统。

在下面的管理cmd中运行

mongod --remove

这将删除现有的MongoDB服务(如果有的话)。

mongod --dbpath "C:\data\db" --logpath "C:\Program Files\MongoDB\Server\3.4\bin\mongod.log" --install --serviceName "MongoDB"

确认C:\data\db文件夹存在

使用以下工具开放服务:

services.msc

Find MongoDB ->右键单击->开始

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

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

就是这样!