MongoDB 学习笔记之 分析器和explain

时间:2017-09-03 20:48:36   收藏:0   阅读:316

MongoDB分析器:

 

检测MongoDB分析器是否打开:

db.getProfilingLevel()

技术分享

db.setProfilingLevel(2)

技术分享

此时发现在test数据库下多了一个system.profile集合:不过此时这个集合还是空的。

技术分享

然后我们进行一次查询db.comments.find({timestamp: 6})

技术分享

然后再查询集合:db.system.profile.find().pretty(),我们可以看到刚才查询的执行计划。

"nReturned" : 1返回行数1

 "millis" : 0 执行时间

"stage" : "COLLSCAN" 未使用索引

"docsExamined" : 8 一共扫描了8个文档

技术分享

由此可见,我们可以通过语句:db.system.profile.find({"query.find": "comments"}).sort({"ts": -1}).limit(1).pretty() 查询出指定语句中最新的执行计划。

system.profile集合的默认大小为1024KB=1MB,我们来扩大它的大小:

  1. 关闭MongoDB分析器
  2. 删除system.profile集合
  3. 创建50M固定大小的集合

技术分享

 

 MongoDB explain:

用explain分析特定的查询

db.comments.find({timestamp: 6}).explain(true)

技术分享

 

原文:http://www.cnblogs.com/AK47Sonic/p/7470815.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!