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-23 15:50:05 -0400 |
commit | 8b8845703f0c92bafca58ce5d9f36fd2327301d1 (patch) | |
tree | 6f9d3f5aac05d75f6ecead8db7941613650957bb /jstests/aggregation | |
parent | a69ae445303fc4821c6745866b3902623a385c1c (diff) | |
download | mongo-8b8845703f0c92bafca58ce5d9f36fd2327301d1.tar.gz |
SERVER-29647 Fix $match swapping to avoid moving before $sort-$limit.
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()); +}()); |