(1)下載mongodb
window版本:http://www.mongodb.org/dr/downloads.mongodb.org/win32/mongodb-win32-i386-1.8.3.zip/download
(2)、設置MongoDB目錄(解壓zip文件) 將其解壓到 d:\,再重命名爲mongodb,路徑爲d:\mongodb (3)、設置數據文件路徑,在d:盤建一個db文件夾,路徑d:\mongodb\db。啓動mongodb服務之前需要必須創建數據庫文件的存放文件夾,否則命令不會自動創建,而且不能啓動成功。默認文件夾路徑爲c:/data/db.使用系統默認文件夾路徑時,啓動服務無需加--dbpath 參數說明,但文件夾還要手工創建
(4)、啓動MongoDB服務 進入 cmd 提示符控制檯,D:\mongodb\bin\mongod.exe --dbpath=d:\mongodb\db
顯示:
Microsoft Windows [版本 6.1.7600] 版權所有 (c) 2009 Microsoft Corporation。保留所有權利。 D:\>cd developtools D:\developtools>cd mongodb D:\developtools\mongodb>cd bin D:\developtools\mongodb\bin>mongod.exe --dbpath=D:\developtools\mongodb\data Mon Sep 05 21:25:12 [initandlisten] MongoDB starting : pid=4920 port=27017 dbpat h=D:\developtools\mongodb\data 32-bit ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data ** see http://blog.mongodb.org/post/137788967/32-bit-limitations ** with --dur, the limit is lower Mon Sep 05 21:25:12 [initandlisten] db version v1.8.3, pdfile version 4.5 Mon Sep 05 21:25:12 [initandlisten] git version: c206d77e94bc3b65c76681df5a6b605 f68a2de05 Mon Sep 05 21:25:12 [initandlisten] build sys info: windows (5, 1, 2600, 2, 'Ser vice Pack 3') BOOST_LIB_VERSION=1_35 Mon Sep 05 21:25:12 [initandlisten] waiting for connections on port 27017 Mon Sep 05 21:25:12 [websvr] web admin interface listening on port 28017
表示啓動成功,最後兩行說明的數據庫端口和Web端口,默認分別是27017和28017,在瀏覽器中打開http://localhost:28017,可以看到其相關的一些信息。
可以通過添加參數--port的方式,來修改數據庫端口:D:/mongodb/bin>mongod.exe --port 10001 --dbpath D:/mongodb/data/db
5.再打開一個cmd輸入:D:/mongodb/bin>mongo,或者雙擊mongo.exe,即可進行mongodb的客戶端命令操作了,測試下
>// the mongo shell is a javascript shell connected to the db
> 3+3
6
> db
test
> // the first write will create the db:
> db.foo.insert( { a : 1 } )
> db.foo.find()
{ _id : ..., a : 1 }
(5)、將MongoDB作爲 Windows 服務隨機啓動.像上面操作每次啓動MongoDB很不方便,我們可以像安裝的MySQL一樣,把它作爲Windows服務,這樣就方便多了。
安裝MongoDB的windows服務的方法爲是在MongoDB安裝目錄下創建logs目錄,然後在CMD命令行輸入
E:/mongodb/bin>mongod --logpath D:/mongodb/logs/mongodb.log --logappend
--dbpath D:/mongodb/data/db --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"'.
表示服務創建成功。
該命令行指定了日誌文件:/logs/MongoDB.log,日誌是以追加的方式輸出的;
數據文件目錄:/data/db,並且參數--directoryperdb說明每個DB都會新建一個目錄;
Windows服務的名稱:MongoDB;
以上的三個參數都是可以根據自己的情況而定的。
最後是安裝參數:--install,與之相對的是--remove
(6)以後就可以在cmd下用命令net start MongoDB和net stop MongoDB來啓動和停止MongoDB了,也可以在本地服務中看到通過界面來管理該服務。