阴谋与爱情露伊斯独白:第二章 MongoDb初体验

来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 17:07:15
第二章 MongoDb初体验 2010-07-01 18:45:35标签:体验 MongoDb 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jooben.blog.51cto.com/253727/342401

第二章 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盘

 3、创建默认存储的文件夹(\data\db)

 

 即:C:\data\db

 4、启动mongodb服务器端

 C:\mongodb>cd bin

 C:\mongodb\bin>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>mongo.exe

 MongoDB shell version: 1.4.3

 url: test

 connecting to: test

 

 

type "exit" to exit

 

 

type "help" for help

 

 

> db.foo.save({a:1})

 

 

> db.foo.findOne()

 

 

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

 

 

> 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

 

 

     当为从时,指定主的地址和端口

 

 

--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服务器

 

 

本文出自 “leolee” 博客,请务必保留此出处http://jooben.blog.51cto.com/253727/342401