mongodb也提供explain命令,来查看执行计划,可以查看系统的是否用到索引,是怎么使用索引,针对性的对查询进行优化。
先看一个例子
> db.post.find().explain()
{
"cursor" : "BasicCursor",
"indexBounds" : [ ],
"nscanned" : 40,
"nscannedObjects" : 40,
"n" : 40,
"millis" : 0,
"allPlans" : [
{
"cursor" : "BasicCursor",
"indexBounds" : [ ]
}
]
}
cursor这个是返回的游标类型,这里是BasicCursor,还有Btree
"nscanned" : 40被扫描的文档数量
n返回的数量 ,这里全部返回,所以也是40
millis消耗的时间
indexBounds为空的,说明没有用到索引
本文通过实例展示了MongoDB的explain命令如何帮助我们理解查询执行计划,包括是否利用索引及其效率,为查询优化提供依据。
1972

被折叠的 条评论
为什么被折叠?



