Fixed $elemMatch with logical operators in Minimongo.

See: https://github.com/meteor/meteor/issues/3427
This commit is contained in:
Mitar
2016-01-11 11:16:19 +01:00
parent a28aa7f95c
commit ef5481d3d5
2 changed files with 16 additions and 1 deletions

View File

@@ -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});

View File

@@ -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 {