MongoDBCompass shell 解释不遵守详细参数

问题描述

使用:MongoDB 4.2.3 社区版和 MongoSH Beta

当我对聚合查询运行解释时,无论我为详细参数提供什么,我都会得到 queryPlanner 输出

例如:

db.myCollection.aggregate([{$match: {
  "entry.active" : true
}}]).explain("executionStats")

返回

{ queryPlanner: 
   { plannerVersion: 1,namespace: 'myDb.myCollection',indexFilterSet: false,parsedQuery: { 'entry.active': { '$eq': true } },queryHash: '53DDBAB6',planCacheKey: '53DDBAB6',optimizedPipeline: true,winningPlan: 
      { stage: 'COLLSCAN',filter: { 'entry.active': { '$eq': true } },direction: 'forward' },rejectedplans: [] },serverInfo: 
   { host: 'zzzzz',port: 11111,version: '4.2.3',gitVersion: '6874650b362138df74be53d366bbefc321ea32d4' },ok: 1 }

无论我提供“executionStats”、“allPlansExecution”还是true作为解释参数,输出都是一样的。

有什么方法可以让我获得 Compass 中聚合查询的更详细的解释细节吗?

解决方法

聚合管道中的解释参数记录为 here,它只有一个布尔值(解释或不解释)。

据我所知,没有规定可以从聚合管道中获取执行统计信息。

为了比较,非聚合解释的解释详细程度记录在here中。

我的猜测是,因为聚合管道可以包含多个阶段,所以执行统计数据不像本质上是单阶段查找那样容易呈现,因此没有实现此功能。

,

在 D.SM 的问题之后,我意识到我正在查看 cursor.explain 文档而不是aggregate.explain 文档。后者明确说明

您也不能指定说明选项。

https://docs.mongodb.com/manual/reference/method/db.collection.aggregate/#db.collection.aggregate