【问题标题】:MongoDB: Try to get explanation on aggregationMongoDB:尝试获取有关聚合的解释
【发布时间】:2016-06-21 11:24:11
【问题描述】:

我尝试使用{explain:true} 获取有关我在 MongoDB 3.2.5 上所做的聚合的信息,以查看是否使用了我的索引:

db.mycollection.aggregate([{
  "$geoNear": {
    "near": {
      type: "Point",
      coordinates: [2.48043, 49.14128]
    },
    "spherical": true,
    "distanceField": "distance",
    "maxDistance": 500
  }
}, {
  "$match": {
    "date": {
      $gt: new ISODate("2016-01-01T01:01:01Z")
    }
  }
}, {
  "$sort": {
    "score": -1,
    "distance": 1
  }
}], {
  explain: true
});

结果我只得到了阶段聚合:

{
  "waitedMS": NumberLong(0),
  "stages": [{
    "$geoNear": {
      "near": {
        "type": "Point",
        "coordinates": [
          2.48043,
          49.14128
        ]
      },
      "distanceField": "distance",
      "limit": NumberLong(100),
      "maxDistance": 500,
      "query": {

      },
      "spherical": true,
      "distanceMultiplier": 1
    }
  }, {
    "$match": {
      "date": {
        "$gt": ISODate("2016-01-01T01:01:01Z")
      }
    }
  }, {
    "$sort": {
      "sortKey": {
        "score": -1,
        "distance": 1
      }
    }
  }],
  "ok": 1
}

我没有关于扫描的文档、使用的索引等的任何信息...

有人可以帮帮我吗?

【问题讨论】:

    标签: mongodb aggregation-framework mongodb-indexes


    【解决方案1】:

    按照说明书

    该操作返回一个光标,其文档包含 有关聚合处理的详细信息 管道。例如,该文件可能会显示,除其他细节外, 使用了哪个索引(如果有)。

    所以有一种歧义,但如果你将$geoNear$match 交换 - 解释应该会显示更多内容。

    【讨论】:

    • 如果我按照手册进行操作,$geoNear 必须是聚合管道中的第一阶段...不?
    • ok @CedricLecocq 这可能是解释条目中不包含索引的原因(以及无法使用它们的事件)
    • 我试图交换 $geoNear 和 $match 但我得到了一个错误,正如我所料...如果我删除 $geoNear 阶段,我会在解释中得到一个 $cursor 阶段,其中包含此类信息我正在寻找...
    猜你喜欢
    • 2020-03-21
    • 2012-09-24
    • 1970-01-01
    • 2019-10-09
    • 2019-04-08
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 2019-05-26
    相关资源
    最近更新 更多