假如想把日誌文件和數據庫文件存放在 D:\mongodb-v3.3.14\
目錄,則在這個目錄下建立 logs
文件夾和 data
文件夾。mongodb
用新建立的兩個文件夾的路徑,替換如下命令行中的 D:\mongodb-v3.3.14\logs\MongoDB.log
和 D:\mongodb-v3.3.14\data
數據庫
mongod --logpath D:\mongodb-v3.3.14\logs\MongoDB.log --logappend --dbpath D:\mongodb-v3.3.14\data --directoryperdb --serviceName MongoDB --install
定位到 MongoDB
的 bin
目錄下,以管理員權限執行以上命令行。windows
查看 logs
文件夾下的 MongoDB.log
日誌文件,若是出現如下字符串 [main] Service can be started from the command line with 'net start MongoDB'
,證實服務安裝成功。app
命令行運行 net start MongoDB
啓動 MongoDB
的 windows
服務。命令行
若是想中止服務,則在命令行中運行 net stop MongoDB
。日誌
若是想刪除 MongoDB 的 windows 服務,則定位到 MongoDB的bin目錄
下,以管理員權限執行命令行 mongod --remove
。code