From ef5481d3d5a78ea3f09ea7f573c3f4b2b8bf9242 Mon Sep 17 00:00:00 2001 From: Mitar Date: Mon, 11 Jan 2016 11:16:19 +0100 Subject: [PATCH] Fixed $elemMatch with logical operators in Minimongo. See: https://github.com/meteor/meteor/issues/3427 --- packages/minimongo/minimongo_tests.js | 15 +++++++++++++++ packages/minimongo/selector.js | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/minimongo/minimongo_tests.js b/packages/minimongo/minimongo_tests.js index 973152f0db..76b9e25b0d 100644 --- a/packages/minimongo/minimongo_tests.js +++ b/packages/minimongo/minimongo_tests.js @@ -1135,6 +1135,12 @@ Tinytest.add("minimongo - selector_compiler", function (test) { {a: [{x: 1, b: 1}]}); match({a: {$elemMatch: {$or: [{a: 1}, {b: 1}], x: 1}}}, {a: [{x: 1, b: 1}]}); + match({a: {$elemMatch: {$or: [{a: 1}, {b: 1}]}}}, + {a: [{x: 1, b: 1}]}); + match({a: {$elemMatch: {$or: [{a: 1}, {b: 1}]}}}, + {a: [{x: 1, b: 1}]}); + match({a: {$elemMatch: {$and: [{b: 1}, {x: 1}]}}}, + {a: [{x: 1, b: 1}]}); nomatch({a: {$elemMatch: {x: 1, $or: [{a: 1}, {b: 1}]}}}, {a: [{b: 1}]}); nomatch({a: {$elemMatch: {x: 1, $or: [{a: 1}, {b: 1}]}}}, @@ -1142,6 +1148,15 @@ Tinytest.add("minimongo - selector_compiler", function (test) { nomatch({a: {$elemMatch: {x: 1, $or: [{a: 1}, {b: 1}]}}}, {a: [{x: 1}, {b: 1}]}); + test.throws(function () { + match({a: {$elemMatch: {$gte: 1, $or: [{a: 1}, {b: 1}]}}}, + {a: [{x: 1, b: 1}]}); + }); + + test.throws(function () { + match({x: {$elemMatch: {$and: [{$gt: 5, $lt: 9}]}}}, {x: [8]}); + }); + // $comment match({a: 5, $comment: "asdf"}, {a: 5}); nomatch({a: 6, $comment: "asdf"}, {a: 5}); diff --git a/packages/minimongo/selector.js b/packages/minimongo/selector.js index be9c9df281..145487be82 100644 --- a/packages/minimongo/selector.js +++ b/packages/minimongo/selector.js @@ -681,7 +681,7 @@ ELEMENT_OPERATORS = { throw Error("$elemMatch need an object"); var subMatcher, isDocMatcher; - if (isOperatorObject(operand, true)) { + if (isOperatorObject(_.omit(operand, _.keys(LOGICAL_OPERATORS)), true)) { subMatcher = compileValueSelector(operand, matcher); isDocMatcher = false; } else {