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为空的,说明没有用到索引

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐