MongoDB的索引(四)

创建索引的好处是可以加快查询速度,但是但来的负面影响就是磁盘的开销和降低写入性嫩。

查看评判当前索引构建情况方法:


1. 使用mongostat工具: 查看mongodb运行状态的程序

使用格式:mongostat -h 127.0.0.1:12345


2. profile集合使用

db.getProfilingStatus()  查看当前的profile的设置

> db.getProfilingStatus()
{ "was" : 0, "slowms" : 100 }
> db.setProfilingLevel(2)
{ "was" : 0, "slowms" : 100, "ok" : 1 }

有3个级别可设置,0,1,2

设置为2MongoDB会记录所有操作

> db.system.profile.find().sort({$natural:-1}).limit(1)
{ "op" : "query", "ns" : "test.system.profile", "query" : { "query" : {  }, "orderby" : { "$natural" : -1 } }, "ntoreturn" : 10, "ntoskip" : 0, "nscan
ned" : 0, "nscannedObjects" : 0, "keyUpdates" : 0, "writeConflicts" : 0, "numYield" : 0, "locks" : { "Global" : { "acquireCount" : { "r" : NumberLong(
2) } }, "MMAPV1Journal" : { "acquireCount" : { "r" : NumberLong(1) } }, "Database" : { "acquireCount" : { "r" : NumberLong(1) } }, "Collection" : { "a
cquireCount" : { "R" : NumberLong(1) } } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "execStats" : { "stage" : "COLLSCAN", "filter" : { "
$and" : [ ] }, "nReturned" : 0, "executionTimeMillisEstimate" : 0, "works" : 2, "advanced" : 0, "needTime" : 1, "needFetch" : 0, "saveState" : 0, "res
toreState" : 0, "isEOF" : 1, "invalidates" : 0, "direction" : "backward", "docsExamined" : 0 }, "ts" : ISODate("2015-08-27T15:20:51.434Z"), "client" :
 "127.0.0.1", "allUsers" : [ ], "user" : "" }


3. 日志介绍

日志会记录MongoDB运行状态,连接等等信息。


4. explain分析

使用该参数可以显示某次查询的详细结果

db.location.find({x:1}).explain()

> db.bochao.find({x:10}).explain()
{
        "queryPlanner" : {
                "plannerVersion" : 1,
                "namespace" : "bochao.bochao",
                "indexFilterSet" : false,
                "parsedQuery" : {
                        "x" : {
                                "$eq" : 10
                        }
                },
                "winningPlan" : {
                        "stage" : "COLLSCAN",
                        "filter" : {
                                "x" : {
                                        "$eq" : 10
                                }
                        },
                        "direction" : "forward"
                },
                "rejectedPlans" : [ ]
        },
        "serverInfo" : {
                "host" : "dcz1001-PC",
                "port" : 27017,
                "version" : "3.0.5",
                "gitVersion" : "8bc4ae20708dbb493cb09338d9e7be6698e4a3a3"
        },
        "ok" : 1





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值