MongoDBCompass shell explain does not honor verbosity parameter

1.9k views Asked by At

Using: MongoDB 4.2.3 Community edition and the MongoSH Beta

When I run explain on an aggregate query, I get the queryPlanner output regardless of what I supply for the verbose parameter.

Ex:

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

returns

{ 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 }

The output is the same whether I supply "executionStats", "allPlansExecution", or true as the parameter to explain.

Is there some way I can get the more verbose explain details for an aggregate query in Compass?

2

There are 2 answers

1
D. SM On

The explain parameter in aggregation pipelines is documented here and it only has a boolean value (explain or don't explain).

There is no provision as far as I can tell to obtain execution stats from aggregation pipeline explains.

For comparison, the explain verbosity for non-aggregation explain is documented here.

My guess is, because aggregation pipeline can contain multiple stages, the execution statistics aren't presentable as easily as they would be for what essentially is a single-stage find, so this functionality wasn't implemented.

1
pierus On

After D.SM's question, I realized I was looking the cursor.explain docs instead of the aggregate.explain docs. The latter explicitly state

You also cannot specify the explain option.

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