[SERVER-12936] Passing explain option to aggregation framework doesn't work with shell helper Created: 27/Feb/14  Updated: 06/Mar/14  Resolved: 06/Mar/14

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 2.6.0-rc0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Alvin Richards (Inactive) Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

See above

Participants:

 Description   

Problem:
Based on the doc
http://docs.mongodb.org/master/reference/method/db.collection.aggregate/#db.collection.aggregate

Passing in the explain option causes the following

> db.sbtest5.aggregate({ $match: { _id: { $gte: 407091, $lte: 407190 } } }, { $project: { k: 1 , _id: 0 } }, { $group: { _id: null, average: { $sum: "$k" } } }, {explain:true})
assert: command failed: {
	"errmsg" : "exception: Unrecognized pipeline stage name: 'explain'",
	"code" : 16436,
	"ok" : 0
} : aggregate failed
Error: command failed: {
	"errmsg" : "exception: Unrecognized pipeline stage name: 'explain'",
	"code" : 16436,
	"ok" : 0
} : aggregate failed
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at Function.assert.commandWorked (src/mongo/shell/assert.js:244:5)
    at DBCollection.aggregate (src/mongo/shell/collection.js:1098:12)
    at (shell):1:12
2014-02-27T09:57:34.905-0800 Error: command failed: {
	"errmsg" : "exception: Unrecognized pipeline stage name: 'explain'",
	"code" : 16436,
	"ok" : 0
} : aggregate failed at src/mongo/shell/assert.js:13



 Comments   
Comment by Mathias Stearn [ 28/Feb/14 ]

The varargs form of calling aggregate() is deprecated and intentionally doesn't support options. If you want to pass options you must use the new style API aggregate([pipeline], {optional options}). For 2.6 all docs should be updated to use the new api.

dan@10gen.com That wouldn't work since it puts the options inside the $match stage. It needs to be separate.

Comment by Daniel Pasette (Inactive) [ 27/Feb/14 ]

might be hard to do because the pipeline is of arbitrary length and the array delimits it. maybe by naming the aggOptions?

> db.coll.aggregate({ $match: { _id: 407091 }, aggOptions: { explain: true, allowDiskUse: true, ... } } );

Comment by Alvin Richards (Inactive) [ 27/Feb/14 ]

Ok, the problem is resolved by wrapping the aggr pipeline in an array

> db.sbtest5.aggregate([{ $match: { _id: { $gte: 407091, $lte: 407190 } } }, { $project: { k: 1 , _id: 0 } }, { $group: { _id: null, average: { $sum: "$k" } } }], {explain:true})

Usability issue that should be fixed.

Generated at Thu Feb 08 03:30:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.