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 {