|
|
@ -85,12 +85,21 @@ Cursor.prototype._exec = function(callback) { |
|
|
|
keys = Object.keys(this._sort); |
|
|
|
keys = Object.keys(this._sort); |
|
|
|
|
|
|
|
|
|
|
|
// Going backwards so that the first sort is the last that gets applied
|
|
|
|
// Going backwards so that the first sort is the last that gets applied
|
|
|
|
for (i = keys.length - 1; i >= 0; i -= 1) { |
|
|
|
var criteria = []; |
|
|
|
|
|
|
|
for (i = 0; i < keys.length; i++) { |
|
|
|
key = keys[i]; |
|
|
|
key = keys[i]; |
|
|
|
|
|
|
|
criteria.push({ key: key, direction: self._sort[key] }); |
|
|
|
|
|
|
|
} |
|
|
|
res.sort(function(a, b) { |
|
|
|
res.sort(function(a, b) { |
|
|
|
return self._sort[key] * model.compareThings(model.getDotValue(a, key), model.getDotValue(b, key)); |
|
|
|
for (var i = 0; i < criteria.length; i++) { |
|
|
|
});
|
|
|
|
var criterion = criteria[i]; |
|
|
|
|
|
|
|
var compare = criterion.direction * model.compareThings(model.getDotValue(a, criterion.key), model.getDotValue(b, criterion.key)); |
|
|
|
|
|
|
|
if (compare !== 0) { |
|
|
|
|
|
|
|
return compare; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Applying limit and skip
|
|
|
|
// Applying limit and skip
|
|
|
|
var limit = this._limit || res.length |
|
|
|
var limit = this._limit || res.length |
|
|
|