diff --git a/packages/minimongo/minimongo_tests.js b/packages/minimongo/minimongo_tests.js index 4f2fa6a41b..2b0cd57b90 100644 --- a/packages/minimongo/minimongo_tests.js +++ b/packages/minimongo/minimongo_tests.js @@ -469,9 +469,6 @@ Tinytest.add("minimongo - selector_compiler", function (test) { match({a: {$ne: {x: 1}}}, {a: {x: 1, y: 2}}); // This query means: All 'a.b' must be non-5, and some 'a.b' must be >6. - // Current bad code parses this as "All 'a.b' must be both non-5 and >6", so - // it doesn't allow for some 'a.b' to be <5. - test.expect_fail(); match({'a.b': {$ne: 5, $gt: 6}}, {a: [{b: 2}, {b: 10}]}); nomatch({'a.b': {$ne: 5, $gt: 6}}, {a: [{b: 2}, {b: 4}]}); nomatch({'a.b': {$ne: 5, $gt: 6}}, {a: [{b: 2}, {b: 5}]}); diff --git a/packages/minimongo/selector.js b/packages/minimongo/selector.js index 50c7456247..141d0b53c7 100644 --- a/packages/minimongo/selector.js +++ b/packages/minimongo/selector.js @@ -228,19 +228,26 @@ var LOGICAL_OPERATORS = { } }; +var invertBranchedSelector = function (branchedSelector) { + // Note that this implicitly "deMorganizes" the wrapped function. ie, it + // means that ALL branch values need to fail to match innerBranchedSelector. + return function (branchValues, doc) { + var invertMe = branchedSelector(branchValues, doc); + // We explicitly choose to strip arrayIndex here: it doesn't make sense to + // say "update the array element that does not match something", at least + // in mongo-land. + return {result: !invertMe.result}; + }; +}; + // XXX doc var VALUE_OPERATORS = { $not: function (operand, operator, cursor) { - var innerBranchedSelector = compileValueSelector(operand, cursor); - // Note that this implicitly "deMorganizes" the wrapped function. ie, it - // means that ALL branch values need to fail to match innerBranchedSelector. - return function (branchValues, doc) { - var invertMe = innerBranchedSelector(branchValues, doc); - // We explicitly choose to strip arrayIndex here: it doesn't make sense to - // say "update the array element that does not match something", at least - // in mongo-land. - return {result: !invertMe.result}; - }; + return invertBranchedSelector(compileValueSelector(operand, cursor)); + }, + $ne: function (operand) { + return invertBranchedSelector(convertElementSelectorToBranchedSelector( + equalityElementSelector(operand))); } };