第6周 处理非结构化数据的利器Mongodb

mongodb:面向文档的nosql

mongodb官网:http://www.mongodb.org/
10gen官网:http://www.mongodb.com/
面向文档的存储引擎,可以方便的支持非结构化数据
全面的索引支持,可以在任意属性上建立索引
数据库本身内置的复制与高可用
数据库本身支持的自动分片集群
丰富的基于文档的查询功能
原子化的数据操作

非结构化数据
不能确定表的列结构的数据
例子:调查表
集合
集合就是一组文档
文档类似于关系数据库里的行
集合类似于关系数据库里的表
集合是无模式的,即集合中的文档可以五花八门,无需固定结构
数据库是由多个集合组成

mongodb的安装:

# tar zxvf mongodb-linux-i686-2.0.9.tgz                --解压
# mv mongodb-linux-i686-2.0.9 mongodb              --重命名
# cd mongodb
# mkdir data                                                       --data目录存放数据
# mkdir log                                                         -- log目录存放日志
# cd bin/                                                         -- 然后定位到mongodb/bin目录中
## 启动服务
[root@linux bin]# ./mongod --dbpath=/nosql/mongodb/mongodb/data/ --logpath=/nosql/mongodb/mongodb/log/mongodb.log
all output going to: /nosql/mongodb/mongodb/log/mongodb.log

[root@linux ~]# ps -ef | grep mongo
root 3936 3047 0 18:45 pts/0 00:00:00 ./mongod --dbpath=/nosql/mongodb/mongodb/data/ --logpath=/nosql/mongodb/mongodb/log/mongodb.log
root 3975 3946 0 18:46 pts/1 00:00:00 grep mongo
[root@linux ~]# pstree -p | grep mongo
        |-sshd(2713)-+-sshd(3045)---bash(3047)---mongod(3936)-+-{mongod}(3937)
        | | |-{mongod}(3938)
        | | |-{mongod}(3939)
        | | |-{mongod}(3940)
        | | |-{mongod}(3941)
        | | |-{mongod}(3942)
        | | `-{mongod}(3943)

通过配置文件来启动Mongodb

[root@linux bin]# cat mongodb.conf 
logpath=/nosql/mongodb/mongodb/log/mongodb.log
logappend=true                                                              #日志文件自动累加,而不是覆盖
dbpath=/nosql/mongodb/mongodb/data/
pidfilepath=/nosql/mongodb/mongodb/log/mongodb.pid
fork=true                                                                     #加了fork,就会丢后台运行
[root@linux bin]# ./mongod -f /nosql/mongodb/mongodb/bin/mongodb.conf
[root@linux bin]# forked process: 4004
all output going to: /nosql/mongodb/mongodb/log/mongodb.log
[root@linux bin]# pstree -p | grep mongo
        |-mongod(4004)-+-{mongod}(4005)
        | |-{mongod}(4006)
        | |-{mongod}(4007)
        | |-{mongod}(4008)
        | |-{mongod}(4009)
        | |-{mongod}(4010)
        | `-{mongod}(4011)

测试javascript:

[root@linux bin]# ./mongo
MongoDB shell version: 2.0.9
connecting to: test
> 40/5
8
> x=200
200
> db.foo.save({a:1});
> db.foo.find();
{ "_id" : ObjectId("52b815edda39a9573226cb88"), "a" : 1 }   ##_id用于唯一标示文档,类似oracle里的rowid
> exit                                                      ##objectid是id的缺省产生办法
bye
[root@linux bin]#

常用命令 :

如果想查看当前连接在哪个数据库下面,可以直接输入db
查看用户列表db.system.users.find();
查看所有用户show users;
查看所有数据库show dbs;
查看所有集合show collections;
删除当前的数据库db.dropDatabase();
删除collection db.集合名.drop();
想知道mongodb执行哪些命令,可以直接输入help;
想知道当前数据库支持哪些方法db.help();
想知道当前集合支持哪些方法db.集合名.help();

MongoDb web 用户界面

在比MongoDB服务的端口多1000的端口上,你可以访问到MondoDB的web用户界面。

如:如果你的MongoDB运行端口使用默认的27017,你可以在端口号为28017访问web用户界面。

http://192.168.253.128:28017/


mongod -help

[root@linux bin]# ./mongod -help
Allowed options:
General options:
  -h [ --help ] show this usage information
  --version show version information
  -f [ --config ] arg configuration file specifying additional options
  -v [ --verbose ] be more verbose (include multiple times for more
                              verbosity e.g. -vvvvv)
  --quiet quieter output
  --port arg specify port number - 27017 by default
  --bind_ip arg comma separated list of ip addresses to listen on
                              - all local ips by default
  --maxConns arg max number of simultaneous connections - 20000 by
                              default
  --logpath arg log file to send write to instead of stdout - has
                              to be a file, not directory
  --logappend append to logpath instead of over-writing
  --pidfilepath arg full path to pidfile (if not set, no pidfile is
                              created)
  --keyFile arg private key for cluster authentication
  --setParameter arg Set a configurable parameter
  --nounixsocket disable listening on unix sockets
  --unixSocketPrefix arg alternative directory for UNIX domain sockets
                              (defaults to /tmp)
  --fork fork server process
  --syslog log to system's syslog facility instead of file
                              or stdout
  --auth run with security
  --cpu periodically show cpu and iowait utilization
  --dbpath arg directory for datafiles - defaults to /data/db/
  --diaglog arg 0=off 1=W 2=R 3=both 7=W+some reads
  --directoryperdb each database will be stored in a separate
                              directory
  --ipv6 enable IPv6 support (disabled by default)
  --journal enable journaling
  --journalCommitInterval arg how often to group/batch commit (ms)
  --journalOptions arg journal diagnostic options
  --jsonp allow JSONP access via http (has security
                              implications)
  --noauth run without security
  --nohttpinterface disable http interface
  --nojournal disable journaling (journaling is on by default
                              for 64 bit)
  --noprealloc disable data file preallocation - will often hurt
                              performance
  --noscripting disable scripting engine
  --notablescan do not allow table scans
  --nssize arg (=16) .ns file size (in MB) for new databases
  --profile arg 0=off 1=slow, 2=all
  --quota limits each database to a certain number of files
                              (8 default)
  --quotaFiles arg number of files allowed per db, requires --quota
  --repair run repair on all dbs
  --repairpath arg root directory for repair files - defaults to
                              dbpath
  --rest turn on simple rest api
  --shutdown kill a running server (for init scripts)
  --slowms arg (=100) value of slow for profile and console log
  --smallfiles use a smaller default file size
  --syncdelay arg (=60) seconds between disk syncs (0=never, but not
                              recommended)
  --sysinfo print some diagnostic system information
  --upgrade upgrade db if needed
Replication options:
  --oplogSize arg size to use (in MB) for replication op log. default is
                        5% of disk space (i.e. large is good)
Master/slave options (old; use replica sets instead):
  --master master mode
  --slave slave mode
  --source arg when slave: specify master as <server:port>
  --only arg when slave: specify a single database to replicate
  --slavedelay arg specify delay (in seconds) to be used when applying
                        master ops to slave
  --autoresync automatically resync if slave data is stale
Replica set options:
  --replSet arg arg is <setname>[/<optionalseedhostlist>]
  --replIndexPrefetch arg specify index prefetching behavior (if secondary)
                          [none|_id_only|all]
Sharding options:
  --configsvr declare this is a config db of a cluster; default port
                        27019; default dir /data/configdb
  --shardsvr declare this is a shard db of a cluster; default port
                        27018

mongo -help

[root@linux bin]# ./mongo -help
MongoDB shell version: 2.4.8
usage: ./mongo [options] [db address] [file names (ending in .js)]
db address can be:
  foo foo database on local machine
  192.169.0.5/foo foo database on 192.168.0.5 machine
  192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
options:
  --shell run the shell after executing files
  --nodb don't connect to mongod on startup - no
                                        'db address' arg expected
  --norc will not run the ".mongorc.js" file on
                                        start up
  --quiet be less chatty
  --port arg port to connect to
  --host arg server to connect to
  --eval arg evaluate javascript
  -u [ --username ] arg username for authentication
  -p [ --password ] arg password for authentication
  --authenticationDatabase arg user source (defaults to dbname)
  --authenticationMechanism arg (=MONGODB-CR)
                                        authentication mechanism
  -h [ --help ] show this usage information
  --version show version information
  --verbose increase verbosity
  --ipv6 enable IPv6 support (disabled by
                                        default)
file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值