MongoDB 提供了一个 explain 命令让我们获知系统如何处理查询请求。利用 explain 命令,我们可以很好地观察系统如何使用索引来加快检索,同时可以针对性优化索引。
- >db.t5.ensureIndex({name:1})
- >db.t5.ensureIndex({age:1})
- >db.t5.find({age:{$gt:45}},{name:1}).explain()
- {
- "cursor":"BtreeCursorage_1",
- "nscanned":0,
- "nscannedObjects":0,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "n":0,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "millis":0,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "nYields":0,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "nChunkSkips":0,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "isMultiKey":false,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "indexOnly":false,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "indexBounds":{
- "age":[
- [
- 45,108); list-style:decimal-leading-zero outside; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> 1.7976931348623157e+308
- ]
- ]
- }
- }
字段说明: cursor: 返回游标类型(BasicCursor 或 BtreeCursor) nscanned: 被扫描的文档数量 n: 返回的文档数量 millis: 耗时(毫秒) indexBounds: 所使用的索引
原文链接:https://www.f2er.com/nosql/204159.html