windows 安装mongodb

使用以下命令将MongoDB安装成为Windows服务。笔者的MongoDB目录为D:Program Filesmongodb

切换到D:Program Filesmongodbin>

mongod --logpath "D:Program Filesmongodbdatalogs.txt" --logappend --dbpath "D:Program Filesmongodbdata" --directoryperdb --serviceName "MongoDB" --serviceDisplayName "MongoDB" --install

输入以上命令。

Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB"'.

该命令行指定了日志文件:D:Program Filesmongodbdatalogs.tx,日志是以追加的方式输出的;

数据文件目录:D:Program Filesmongodbdata,并且参数--directoryperdb说明每个DB都会新建一个目录;

Windows服务的名称:MongoDB;

最后是安装参数:--install,与之相对的是--remove

启动MongoDB:net start MongoDB


停止MongoDB:net stop MongoDB

注意:遇到问题请查看日志文件

mongodb exception in initAndListen: 12596 old lock file, terminating解决方法

错误信息如下:

exception in initAndListen: 12596 old lock file, terminating

解决方法

1.删除data目录中的.lock文件

2.mongod.exe --repair

3.启动mongod就可以了

from :https://www.cnblogs.com/flyoung2008/archive/2012/07/18/2597269.html

原文地址:https://www.cnblogs.com/shynshyn/p/7965757.html