Move $exists to the new model

Fixes two incompatibilities:
- {$exists: false} did the wrong logic when there were multiple branches
   (we (poorly) special-cased $not and $nin but not this negative case)
- No longer require the argument to $exists to be a boolean;
  {$exists: 0} and {$exists: 1} should work, eg
This commit is contained in:
David Glasser
2013-12-28 23:47:15 -08:00
parent 38a9b08ff6
commit a72c2b89a8
2 changed files with 15 additions and 1 deletions

View File

@@ -433,6 +433,15 @@ Tinytest.add("minimongo - selector_compiler", function (test) {
nomatch({a: {$exists: false}}, {a: [1]});
match({a: {$exists: false}}, {b: [1]});
match({a: {$exists: 1}}, {a: 5});
match({a: {$exists: 0}}, {b: 5});
nomatch({'a.x':{$exists: false}}, {a: [{}, {x: 5}]});
match({'a.x':{$exists: true}}, {a: [{}, {x: 5}]});
match({'a.x':{$exists: true}}, {a: [{}, {x: 5}]});
match({'a.x':{$exists: true}}, {a: {x: []}});
match({'a.x':{$exists: true}}, {a: {x: null}});
// $mod
match({a: {$mod: [10, 1]}}, {a: 11});
nomatch({a: {$mod: [10, 1]}}, {a: 12});

View File

@@ -258,6 +258,12 @@ var VALUE_OPERATORS = {
$nin: function (operand) {
return invertBranchedSelector(convertElementSelectorToBranchedSelector(
ELEMENT_OPERATORS.$in(operand)));
},
$exists: function (operand) {
var exists = convertElementSelectorToBranchedSelector(function (value) {
return value !== undefined;
});
return operand ? exists : invertBranchedSelector(exists);
}
};
@@ -1038,7 +1044,6 @@ var andCompiledDocumentSelectors = function (selectors) {
// Remaining to update:
// - $exists
// - $type
// - $regex/$option
// - $all