-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
ALL
Example:
MongoDB Enterprise > db.t.drop() true MongoDB Enterprise > db.createCollection("t", {timeseries: {timeField: "tf"}}) { "ok" : 1 } MongoDB Enterprise > db.t.aggregate([{$planCacheStats: {}}]) uncaught exception: Error: command failed: { "ok" : 0, "errmsg" : "$planCacheStats is only valid as the first stage in a pipeline.", "code" : 40602, "codeName" : "Location40602" } with original command request: { "aggregate" : "t", "pipeline" : [ { "$planCacheStats" : { } } ], "cursor" : { }, "lsid" : { "id" : UUID("4a3afe13-04c7-4e64-847e-9013a6449132") } } on connection: connection to 127.0.0.1:27017 : aggregate failed : _getErrorWithCode@src/mongo/shell/utils.js:25:13 doassert@src/mongo/shell/assert.js:18:14 _assertCommandWorked@src/mongo/shell/assert.js:719:17 assert.commandWorked@src/mongo/shell/assert.js:811:16 DB.prototype._runAggregate@src/mongo/shell/db.js:276:5 DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1058:12 @(shell):1:1
The error message states that $planCacheStats is not the first stage in the pipeline. This may be confusing to the user, since from the user's perspective it is indeed first in the pipeline. The reason for this error is that the query goes through the view resolution path, which inserts an $_internalUnpackBucket stage at the beginning of the pipeline. Only after view resolution is the constraint about $planCacheStats being first checked.
We should either improve the error message, or better, make $planCacheStats actually work against time-series collections. Note that we have already implemented a special case to allow $indexStats to work; this logic should be extended to $planCacheStats.