温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MongoDB中怎么查看执行计划方法

发布时间:2021-07-16 16:52:40 来源:亿速云 阅读:266 作者:Leah 栏目:关系型数据库

这期内容当中小编将会给大家带来有关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列

上述就是小编为大家分享的MongoDB中怎么查看执行计划方法了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI