MongoDB查看执行计划方法及相关字段说明

> db.chenfeng.find()
{ "_id" : ObjectId("5714419cf7c81959e12a904e"), "age" : 1, "name" : "duansf" }
{ "_id" : ObjectId("571441a3f7c81959e12a904f"), "age" : 2, "name" : "duansf" }
{ "_id" : ObjectId("571441a7f7c81959e12a9050"), "age" : 3, "name" : "duansf" }
{ "_id" : ObjectId("571441abf7c81959e12a9051"), "age" : 4, "name" : "duansf" }
{ "_id" : ObjectId("571442b0f7c81959e12a9052"), "age" : 5, "name" : "duansf" }
{ "_id" : ObjectId("571442bcf7c81959e12a9053"), "age" : 6, "name" : "duansf" }
>


> db.chenfeng.find().explain()
{
        "cursor" : "BasicCursor",
        "isMultiKey" : false,
        "n" : 6,
        "nscannedObjects" : 6,
        "nscanned" : 6,
        "nscannedObjectsAllPlans" : 6,
        "nscannedAllPlans" : 6,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "millis" : 0,
        "server" : "XCC-Duanshufeng:27017",
        "filterSet" : false
}
>

加hint强制使用索引方法,这点和关系数据库特别像:
> db.chenfeng.find().hint({age:6}).explain()
{
        "cursor" : "BtreeCursor idx_age_6",
        "isMultiKey" : false,
        "n" : 6,
        "nscannedObjects" : 6,
        "nscanned" : 6,
        "nscannedObjectsAllPlans" : 6,
        "nscannedAllPlans" : 6,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 1,
        "nChunkSkips" : 0,
        "millis" : 135,
        "indexBounds" : {
                "age" : [
                        [
                                {
                                        "$minElement" : 1
                                },
                                {
                                        "$maxElement" : 1
                                }
                        ]
                ]
        },
        "server" : "XCC-Duanshufeng:27017",
        "filterSet" : false
}


字段说明:
cursor:返回游标类型,有BasicCursor和BtreeCursor,BtreeCursor意味着使用了索引
nscanned:扫描document的行数
nscannedObjects:扫描对象的数量
n:返回的文档行数
millis:耗时(毫秒)
indexBounds:如果不为空,表示此查询使用的索引信息
server:MongoDB所在的服务器名字,27017是端口号


索引的限制:
索引名称不能超过128个字符
每个集合不能超过64个索引
复合索引不能超过31列

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2124452/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2124452/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值