每次運行mongod --dbpath D:/MongoDB/data命令列來啟動MongoDB實在是不方便,就像我免安裝的MySQL一樣,我想把它作為Windows服務,這樣就方便多了。
D:\MongoDB\bin>mongod --logpath D:\MongoDB\logs\MongoDB.log --logappend --dbpath D:\MongoDB\data --directoryperdb --serviceName MongoDB --install
all output going to: D:\MongoDB\logs\MongoDB.log
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB"'.
注意:這條命令要到MongoDB的bin目錄下運行,剛開始的時候,我就直接在D:\下運行,結果服務的可執行目錄為【"D:\mongod" --logpath "D:\MongoDB\logs\MongoDB.log" --logappend --dbpath "D:\MongoDB\data" --directoryperdb --service 】,肯定是不對的。
該命令列指定了記錄檔:D:\MongoDB\logs\MongoDB.log,日誌是以追加的方式輸出的;
資料檔案目錄:D:\MongoDB\data,並且參數--directoryperdb說明每個DB都會建立一個目錄;
Windows服務的名稱:MongoDB;
以上的三個參數都是可以根據自己的情況而定的,呵呵。
最後是安裝參數:--install,與之相對的是--remove
啟動MongoDB:net start MongoDB
停止MongoDB:net stop MongoDB