diff options
author | David Storch <david.storch@10gen.com> | 2017-06-21 15:07:52 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2017-06-26 15:57:27 -0400 |
commit | 8bc18f2367d616ef1e68b3be4acfaa1d2e8daa6e (patch) | |
tree | 90b1a2bf186a9901fca1b4c901a0ce6212793cc9 /jstests/aggregation | |
parent | de969ba464dfe0e3d5ffd45dd4f5b6cec824e775 (diff) | |
download | mongo-8bc18f2367d616ef1e68b3be4acfaa1d2e8daa6e.tar.gz |
SERVER-29647 Fix $match swapping to avoid moving before $sort-$limit.
(cherry picked from commit 8b8845703f0c92bafca58ce5d9f36fd2327301d1)
Conflicts:
jstests/core/views/views_aggregation.js
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/bugs/match_swap_limit.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/jstests/aggregation/bugs/match_swap_limit.js b/jstests/aggregation/bugs/match_swap_limit.js new file mode 100644 index 00000000000..3de26d6f4b5 --- /dev/null +++ b/jstests/aggregation/bugs/match_swap_limit.js @@ -0,0 +1,20 @@ +/** + * Ensure that $match is always applied after $limit. + */ +(function() { + "use strict"; + + let coll = db.jstests_match_swap_limit; + coll.drop(); + + assert.writeOK(coll.insert({_id: 0, x: 1, y: 3})); + assert.writeOK(coll.insert({_id: 1, x: 2, y: 2})); + assert.writeOK(coll.insert({_id: 2, x: 3, y: 1})); + + assert.eq([{_id: 1, x: 2, y: 2}], + coll.aggregate([{$sort: {x: -1}}, {$limit: 2}, {$match: {y: {$gte: 2}}}]).toArray()); + + assert.writeOK(coll.createIndex({x: 1})); + assert.eq([{_id: 1, x: 2, y: 2}], + coll.aggregate([{$sort: {x: -1}}, {$limit: 2}, {$match: {y: {$gte: 2}}}]).toArray()); +}()); |