天天看點

第二章 MongoDb初體驗

第二章 MongoDb初體驗

Windows Xp 下使用MongoDB

1、下載下傳mongodb

mongodb-win32-i386-1.4.3.zip

http://downloads.mongodb.org/win32/mongodb-win32-i386-1.4.3.zip

2、解壓到c盤

<a href="http://jooben.blog.51cto.com/attachment/201007/2/253727_1278037048hXBO.png"></a>

3、建立預設存儲的檔案夾(\data\db)

<a href="http://jooben.blog.51cto.com/attachment/201007/2/253727_1278037049zEVs.png"></a>

即:C:\data\db

4、啟動mongodb伺服器端

C:\mongodb&amp;gt;cd bin

C:\mongodb\bin&amp;gt;mongod.exe

mongod.exe --help for help and startup options

Mon Jun 28 10:40:19 Mongo DB : starting : pid = 0 port = 27017 dbpath = /data/db

/ master = 0 slave = 0  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 for more

Mon Jun 28 10:40:19 db version v1.4.3, pdfile version 4.5

Mon Jun 28 10:40:19 git version: 47ffbdfd53f46edeb6ff54bbb734783db7abc8ca

Mon Jun 28 10:40:19 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LI

B_VERSION=1_35

Mon Jun 28 10:40:19 waiting for connections on port 27017

Mon Jun 28 10:40:19 web admin interface listening on port 28017

,,,,,

看到以上資訊,說明啟動成功。

MongoDB 使用檔案存儲資料. (預設位置 /data/db/), 使用記憶體映射檔案進行高效的資料管理.

MongoDB 程序預設情況下使用監聽端口為 27017  (可以在啟動時用指令行參數修改,詳細資訊參考 [Command Line Parameters] ).

5、簡單測試

這裡調用的是mongo.exe,不是mongodb.exe,要看清楚喲

C:\mongodb\bin&amp;gt;mongo.exe

MongoDB shell version: 1.4.3

url: test

connecting to: test

type "exit" to exit

type "help" for help

&amp;gt; db.foo.save({a:1})

&amp;gt; db.foo.findOne()

{ "_id" : ObjectId("4c280be19764000000005452"), "a" : 1 }

&amp;gt; exit

bye

6、補充參數說明

Allowed options:

General options:

  -h [ --help ]              show this usage information

  --version                  show version information

  -f [ --config ] arg         configuration file specifying additional options

  --port arg                 specify port number

  --bind_ip arg              local ip address to bind listener - all local ips

                            bound by default

  -v [ --verbose ]           be more verbose (include multiple times for more

                            verbosity e.g. -vvvvv)

--dbpath arg (=/data/db/)   directory for datafiles    指定資料存放目錄

  --quiet                    quieter output   靜默模式

  --logpath arg              file to send all output to instead of stdout  指定日志存放目錄

  --logappend                 appnd to logpath instead of over-writing 

指定日志是以追加還是以覆寫的方式寫入日志檔案

  --fork                     fork server process   以建立子程序的方式運作

  --cpu                      periodically show cpu and iowait utilization  周期性的顯示cpu和io的使用情況

  --noauth                   run without security  無認證模式運作

  --auth                     run with security  認證模式運作

--objcheck                 inspect client data for validity on receipt 

檢查用戶端輸入資料的有效性檢查

  --quota      enable db quota management   開始資料庫配額的管理

--quotaFiles arg           number of files allower per db, requires --quota

      規定每個資料庫允許的檔案數

  --appsrvpath arg           root directory for the babble app server 

  --nocursors                diagnostic/debugging option  調試診斷選項

  --nohints                  ignore query hints  忽略查詢命中率

  --nohttpinterface          disable http interface  關閉http接口,預設是28017

  --noscripting              disable scripting engine  關閉腳本引擎

  --noprealloc               disable data file preallocation  關閉資料庫檔案大小預配置設定

  --smallfiles               use a smaller default file size  使用較小的預設檔案大小

--nssize arg (=16)         .ns file size (in MB) for new databases

新資料庫ns檔案的預設大小

--diaglog arg              0=off 1=W 2=R 3=both 7=W+some reads

提供的方式,是隻讀,隻寫,還是讀寫都行,

還是主要寫+部分的讀模式

  --sysinfo                  print some diagnostic system information 列印系統診斷資訊

  --upgrade                  upgrade db if needed  如果需要就更新資料庫

  --repair                   run repair on all dbs  修複所有的資料庫

  --notablescan              do not allow table scans  不運作表掃描

--syncdelay arg (=60)      seconds between disk syncs (0 for never) 

系統同步重新整理磁盤的時間,預設是60s

Replication options:

  --master                master mode 主複制模式

  --slave                 slave mode  從複制模式

--source arg            when slave: specify master as &lt;server:port&gt;

     當為從時,指定主的位址和端口

--only arg              when slave: specify a single database to replicate

當為從時,指定需要從主複制的單一庫

  --pairwith arg          address of server to pair with

--arbiter arg           address of arbiter server

仲裁伺服器,在主主中和pair中用到

  --autoresync            automatically resync if slave data is stale 自動同步從的資料

  --oplogSize arg         size limit (in MB) for op log 指定記錄檔的大小

--opIdMem arg           size limit (in bytes) for in memory storage of op ids

指定存儲記錄檔的記憶體大小

Sharding options:

--configsvr             declare this is a config db of a cluster

指定shard中的配置伺服器

  --shardsvr              declare this is a shard db of a cluster 指定shard伺服器

本文轉自jooben 51CTO部落格,原文連結:http://blog.51cto.com/jooben/342401

上一篇: 跨域通路