mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Support "obj" name in $where
This commit is contained in:
@@ -908,7 +908,9 @@ Tinytest.add("minimongo - selector_compiler", function (test) {
|
||||
|
||||
// $where
|
||||
match({$where: "this.a === 1"}, {a: 1});
|
||||
match({$where: "obj.a === 1"}, {a: 1});
|
||||
nomatch({$where: "this.a !== 1"}, {a: 1});
|
||||
nomatch({$where: "obj.a !== 1"}, {a: 1});
|
||||
nomatch({$where: "this.a === 1", a: 2}, {a: 1});
|
||||
match({$where: "this.a === 1", b: 2}, {a: 1, b: 2});
|
||||
match({$where: "this.a === 1 && this.b === 2"}, {a: 1, b: 2});
|
||||
|
||||
@@ -162,10 +162,14 @@ var LOGICAL_OPERATORS = {
|
||||
|
||||
"$where": function(selectorValue) {
|
||||
if (!(selectorValue instanceof Function)) {
|
||||
selectorValue = Function("return " + selectorValue);
|
||||
// XXX MongoDB seems to have more complex logic to decide where or or not
|
||||
// to add "return"; not sure exactly what it is.
|
||||
selectorValue = Function("obj", "return " + selectorValue);
|
||||
}
|
||||
return function (doc) {
|
||||
return selectorValue.call(doc);
|
||||
// We make the document available as both `this` and `obj`.
|
||||
// XXX not sure what we should do if this throws
|
||||
return selectorValue.call(doc, doc);
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user