mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Implement '$' update for $near
This commit is contained in:
@@ -1805,6 +1805,13 @@ Tinytest.add("minimongo - modify", function (test) {
|
||||
{'a.x': 1, 'a.y': 3},
|
||||
{$set: {'a.$.z': 5}},
|
||||
{a: [{x: 1}, {y: 3, z: 5}]});
|
||||
// with $near, make sure it finds the closest one
|
||||
modifyWithQuery({a: [{b: [1,1]},
|
||||
{b: [ [3,3], [4,4] ]},
|
||||
{b: [9,9]}]},
|
||||
{'a.b': {$near: [5, 5]}},
|
||||
{$set: {'a.$.b': 'k'}},
|
||||
{a: [{b: [1,1]}, {b: 'k'}, {b: [9,9]}]});
|
||||
|
||||
// $inc
|
||||
modify({a: 1, b: 2}, {$inc: {a: 10}}, {a: 11, b: 2});
|
||||
|
||||
@@ -437,22 +437,23 @@ var VALUE_OPERATORS = {
|
||||
// actually show up *multiple times* in the result set, with one entry for
|
||||
// each within-$maxDistance branching point.
|
||||
branchedValues = expandArraysInBranches(branchedValues);
|
||||
var minDistance = null;
|
||||
var result = {result: false};
|
||||
_.each(branchedValues, function (branch) {
|
||||
var curDistance = distance(branch.value);
|
||||
// Skip branches that aren't real points or are too far away.
|
||||
if (curDistance === null || curDistance > maxDistance)
|
||||
return;
|
||||
// Skip anything that's a tie.
|
||||
if (minDistance !== null && minDistance <= curDistance)
|
||||
if (result.distance !== undefined && result.distance <= curDistance)
|
||||
return;
|
||||
minDistance = curDistance;
|
||||
result.result = true;
|
||||
result.distance = curDistance;
|
||||
if (branch.arrayIndex === undefined)
|
||||
delete result.arrayIndex;
|
||||
else
|
||||
result.arrayIndex = branch.arrayIndex;
|
||||
});
|
||||
if (minDistance !== null) {
|
||||
// XXX arrayIndex!
|
||||
return {result: true, distance: minDistance};
|
||||
}
|
||||
return {result: false};
|
||||
return result;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user