MongoDB 学习笔记 1、如何将MongoDB做一项Windows服务启动

注间事项:

1:log一定要指定一个xxx.log文件(文件不存在也要这么写,会自动创建,写成这样是不可以的--logpath d:\mongodb\logs)

2:serviceName的N字母要大写

安装、卸载、重启、停止批处理文件:

安装.bat

@echo off
:start
cls
set /p input=确定安装 MongoDB 吗?[Y/N] 
if %input%==y goto install
if %input%==Y goto install

:install
mongod --logpath D:\MongoDb\logs\MongoDB.log --logappend --dbpath D:\MongoDb\data --directoryperdb --serviceName MongoDB --auth --install
net start MongoDB
pause

卸载.bat

@echo off
:start
cls
set /p input=确定卸载 MongoDB 吗?[Y/N] 
if %input%==y goto remove
if %input%==Y goto remove

:remove
net stop MongoDB
mongod --logpath D:\MongoDb\logs\MongoDB.log --logappend --dbpath D:\MongoDb\data --directoryperdb --serviceName MongoDB --remove
pause

启动.bat

@echo off
:start
cls
set /p input=确定启动 MongoDB 吗?[Y/N] 
if %input%==y goto startMongoDB
if %input%==Y goto startMongoDB

:startMongoDB
net start MongoDB
pause

停止.bat

@echo off
:start
cls
set /p input=确定停止 MongoDB 吗?[Y/N] 
if %input%==y goto stopMongoDB
if %input%==Y goto stopMongoDB

:stopMongoDB
net stop MongoDB
pause

重启.bat

@echo off
:start
cls
set /p input=确定重启 MongoDB 吗?[Y/N] 
if %input%==y goto restartMongoDB
if %input%==Y goto restartMongoDB

:restartMongoDB
net stop MongoDB
net start MongoDB
pause
原文地址:https://www.cnblogs.com/solitary/p/2789209.html