MongoDB(2)

细节

启动服务: -f 配置文件路径,-fork deamon方式启动
关闭服务:use admin -> db.shutdownServer()

cursor

var cursor = db.things.find();
1.while(cursor.hasNext()) {printjson(cursor.next());}
2.cursor.forEach(printjson);
3.cursor[0] (考虑内存溢出)

访问控制

绑定IP –bind_ip
设置监听端口 –port
使用用户名和口令登录 –auth–>db.createUser()–>db.auth();

进程

查看进程:db.currentOp();
干掉进程:db.killOp(opid);

索引(组合,唯一,文档)

创建: db.things.ensureIndex({age:1});
获取:db.things.getIndexes(); {backgroud:true}后台执行;{unique:true}唯一索引
强制使用:db.things.find({age:{$gt:20}}).hint((age:1})
查看索引是否使用:explain()
删除所有:db.things.dropIndexes()
删除指定:db.things.dropIndex({age:1})

性能优化

planA:创建索引,创建索引提高搜索,但以写入减慢为代价
planB:限定返回结果条数
planC:只查使用到的字段,而不查所有字段
planD:采用capped collection,capped collection大小固定,不可delete操作,只可drop;默认基于insert次序排序;FIFO,超过collection大小,新纪录替换最先insert的记录
planE:采用Server Side Code Execution(类似sql数据库的存储过程)
planF:Hint
planG:采用profiling

性能监控

mongosniff从底层监控那些命令发送到Mongodb执行
./mongosniff –source NET lo
mongostat快速查看某组运行中的Mongodb实例
./mongostat
db.serverStatus 查看实例运行状态
db.stats 查看数据库状态信息

http://www.jb51.net/article/48216.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值