diff options
author | Blake Oler <blake.oler@10gen.com> | 2017-10-09 11:48:26 -0400 |
---|---|---|
committer | Blake Oler <blake.oler@10gen.com> | 2017-10-09 11:48:40 -0400 |
commit | 95fedb251673c87b5172269e1f8c116b5e05fb16 (patch) | |
tree | c0fbd29a89addfb6bf54d4630c76772abf6c1564 /jstests/aggregation | |
parent | d7a30a716243db13644a16618a939df6bc1344fc (diff) | |
download | mongo-95fedb251673c87b5172269e1f8c116b5e05fb16.tar.gz |
SERVER-31029 Add support for top-level $expr within $or and $and
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/sources/graphLookup/filter.js | 28 | ||||
-rw-r--r-- | jstests/aggregation/sources/match/expr_match.js | 10 |
2 files changed, 24 insertions, 14 deletions
diff --git a/jstests/aggregation/sources/graphLookup/filter.js b/jstests/aggregation/sources/graphLookup/filter.js index b6eaff41b25..69027500aae 100644 --- a/jstests/aggregation/sources/graphLookup/filter.js +++ b/jstests/aggregation/sources/graphLookup/filter.js @@ -77,18 +77,18 @@ assert.eq(res.results.length, 1); // $expr is allowed inside the 'restrictSearchWithMatch' match expression. - // TODO SERVER-31029: This should not throw once support is added for top-level $expr within $or - // and $and. - assert.throws(function() { - local.aggregate({ - $graphLookup: { - from: "foreign", - startWith: "$starting", - connectFromField: "to", - connectToField: "from", - as: "results", - restrictSearchWithMatch: {$expr: {$eq: ["$shouldBeIncluded", true]}} - } - }); - }); + res = local + .aggregate({ + $graphLookup: { + from: "foreign", + startWith: "$starting", + connectFromField: "to", + connectToField: "from", + as: "results", + restrictSearchWithMatch: {$expr: {$eq: ["$shouldBeIncluded", true]}} + } + }) + .toArray()[0]; + + assert.eq(res.results.length, 1); })(); diff --git a/jstests/aggregation/sources/match/expr_match.js b/jstests/aggregation/sources/match/expr_match.js index 3f2056daf74..b2627c963cc 100644 --- a/jstests/aggregation/sources/match/expr_match.js +++ b/jstests/aggregation/sources/match/expr_match.js @@ -36,4 +36,14 @@ // $match with constant expression and no field path. assert.eq(4, coll.aggregate([{$match: {$expr: {$gte: [10, 5]}}}]).itcount()); assert.eq(0, coll.aggregate([{$match: {$expr: {$gte: [5, 10]}}}]).itcount()); + + // $match with $expr works inside a $or. + assert.eq(4, + coll.aggregate([{$match: {$or: [{$expr: {$eq: ["$foo", "$bar"]}}, {b: {$gt: 3}}]}}]) + .itcount()); + + // $match with $expr works inside a $and. + assert.eq(2, + coll.aggregate([{$match: {$and: [{$expr: {$eq: ["$foo", "$bar"]}}, {x: {$lt: 2}}]}}]) + .itcount()); })(); |