ISSUE SUMMARY
During execution of an aggregation framework pipeline, a combination of an $or query in a $match operator with a subsequent $sort operator on an unindexed field causes the aggregation execution to fail with an exception "exception: cursor encountered an error", error code 17285.
USER IMPACT
The aggregation call fails under the given circumstances, but there is no data loss and the server remains running.
WORKAROUNDS
To work around this bug, place a $project pipeline operator immediately preceding the $sort operator.
Example:
Instead of using this aggregation pipeline:
db.coll.aggregate([ { '$match': { '$or': [ { name: 'red' }, { name: 'blue' }] } }, { '$sort': { value: 1 }}]);
Insert a $project with the desired fields before the $sort:
db.coll.aggregate([ { '$match': { '$or': [ { name: 'red' }, { name: 'blue' }] } }, {'$project': {_id: 1, name: 1, value: 1} }, { '$sort': { value: 1 }}]);
AFFECTED VERSIONS
Versions 2.6.0 and 2.6.1 are affected by this issue.
FIX VERSION
The fix is included in the 2.6.2 production release.
RESOLUTION DETAILS
Subqueries need to be planned on construction of a SubplanRunner rather than from inside the runner in order to fail fast if only blocking sort solutions exist.
Original description
db.orAndSort.aggregate([ { '$match': { '$or': [ { name: 'red' }, { name: 'blue' }] } }, { '$sort': { value: 1 }}]); assert: command failed: { "errmsg" : "exception: cursor encountered an error", "code" : 17285, "ok" : 0 } Detailed error object: { ok: 0.0, code: 2, errmsg: "error processing query: ns=test.orAndSort limit=0 skip=0 Tree: $or name == "red" name == "blue" Sort: { value: 1 } Proj: {} No query solutions" }
There is currently no way to get at the detailed error object without altering the code, but it does show that it is trying to do a sort and failing (due to NO_BLOCKING_SORT) after getRunner returned success.
Related mongodb-users post: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/mongodb-user/YK_D4lJXysY/IHQxX3_sN8EJ
- related to
-
SERVER-14144 Aggregation cursor error message shouldn't swallow Runner error
- Closed