Merge pull request #5968 from mitar/minimongo-elemmatch

Fixed $elemMatch with logical operators in Minimongo
This commit is contained in:
Sashko Stubailo
2016-02-26 12:00:31 -08:00
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 {