close

MongoDB 建議安裝 64 位元版本,因為 32 位元版本最大儲存量只有 2GB 。而在安裝限制的話,Windows 環境下支援 XP 版本以上的作業系統。

資料來源 MongoDB 官方網站

 

1. 下載安裝檔案 
________________________________________
首先進入 MongoDB 網站,在 Downloads 頁面選擇 Windows 64 bit 版本檔案下載,如下圖。

 

2015-09-14_134942  

選擇下載的版本  

Determine which MongoDB build you need.

There are three builds of MongoDB for Windows:

MongoDB for Windows 64-bit runs only on Windows Server 2008 R2, Windows 7 64-bit, and newer versions of Windows. This build takes advantage of recent enhancements to the Windows Platform and cannot operate on older versions of Windows.

MongoDB for Windows 32-bit runs on any 32-bit version of Windows newer than Windows Vista. 32-bit versions of MongoDB are only intended for older systems and for use in testing and development systems. 32-bit versions of MongoDB only support databases smaller than 2GB.

MongoDB for Windows 64-bit Legacy runs on Windows Vista, Windows Server 2003, and Windows Server 2008 and does not include recent performance enhancements.

如果您不知道自己的 Windows 版本,開啟命令提示字元,執行下面的指令即可顯示自己的 Windows 版本:

wmic os get caption
wmic os get osarchitecture

輸出的畫面會類似這樣:

2015-09-14_140413  

執行下的安裝檔,進行安裝。

2015-09-14_141551  

勾選同意使用條款。

install-mongodb-windows-3

選擇安裝的方式,這裡有兩種選項,「Complete」是安裝所有的功能,而「Custom」則是可以讓您自己選擇要安裝的項目。但是依照官網建議是希望安裝在Custom路徑下(C:\mongodb.),預設的路徑是在 Program Files 之下,非常的長,這對於指令的使用非常不方便,您可以將路徑自己修改成類似 C:\MongoDB 這樣比較簡潔的路徑,以便日後使用。基本上安裝的路徑對於 MongoDB 的功能不會有任何影響,唯一的差異只是方便與否。因為我的習慣是建立在C:\Programs\mongodb。

2015-09-14_141514

如果選擇「Complete」的話,就沒有任何選項可以調整。

2015-09-14_141526

您也可以選擇「Custom」,然後依照自己的需求調整,尤其是安裝路徑的部分

2015-09-14_141540  


安裝完成。

install-mongodb-windows-7

安裝完成後,要建立一個資料夾來存放資料庫,MongoDB並不會自己建立,如果沒建立去執行就會看到以下的錯誤

JzufT  

開啟命令提示字元,切換到 MongoDB 安裝路徑下的 bin 目錄,執行

md \data\db

建立放置資料庫的目錄,這個 \data\db 是 MongoDB 預設的資料庫存放路徑。

 接著執行

mongod.exe

如果無法啟動,請確認mongod.exe檔案 (C:\programs\MongoDB\Server\3.0\bin)

這是啟動的畫面:

2015-09-14_141624  

如果沒有錯誤訊息,就表示 MongoDB 已經正常啟動了。

開啟另外一個命令提示字元,切換到MongoDB 安裝路徑下的 bin 目錄,執行

mongo.exe

進入 MongoDB shell 環境。

2015-09-14_141637

這樣就可以開始使用 MongoDB 了。

解說:  mongod.exe 就是啟動Server ,那mongo就是client端去連接Server, 所以如果mongo無法連接上,就是你沒有啟動MongoDB Server

Component Set Binaries
Server mongod.exe
Router mongos.exe
Client mongo.exe
MonitoringTools mongostat.exemongotop.exe
ImportExportTools mongodump.exemongorestore.exemongoexport.exemongoimport.exe
MiscellaneousTools bsondump.exemongofiles.exemongooplog.exemongoperf.exe

客官還沒結束喔!!

Tip: 因為會常用MongoDB shell,建議建立路徑

我的安裝路徑是在C:\Programs\mongodb,所以我整體路徑是C:\programs\MongoDB\Server\3.0\bin

2015-09-14_144758  

到"控制台-->系統與安全-->系統",選擇"改變設定"

2015-09-14_145229

到"進階-->環境變數"

2015-09-14_145307

選擇"路徑",然後按"編輯..."

2015-09-14_145345

把路徑(C:\programs\MongoDB\Server\3.0\bin)加進去 

C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\site\bin;C:\Program Files (x86)\VMware\VMware vSphere CLI\Perl\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files\SlikSvn\bin\;C:\Sun\VirtualBox;C:\Program Files (x86)\Windows Live\Shared;C:\Java\apache-ant-1.8.1\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Mercurial\;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\java\jdk17\bin\;c:\java\maven\bin\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\programs\scala\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\programs\MongoDB\Server\3.0\bin;C:\Python27;C:\Python27\Scripts

2015-09-14_145437

關掉原來的開啟命令提示字元,再重新開啟命令提示字元,執行

 

mongod.exe

 

2015-09-14_145526

 

arrow
arrow
    文章標籤
    MongDB Windows
    全站熱搜

    Kenneth 發表在 痞客邦 留言(0) 人氣()