unread changes

This commit is contained in:
barisusakli
2014-09-27 17:41:49 -04:00
parent 80ca6bb0a2
commit 5fc760c6c4
4 changed files with 76 additions and 48 deletions

View File

@@ -136,14 +136,18 @@ module.exports = function(db, module) {
};
module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
getSortedSetRangeByScore(key, start, count, min, max, 1, callback);
getSortedSetRangeByScore(key, start, count, min, max, 1, false, callback);
};
module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) {
getSortedSetRangeByScore(key, start, count, min, max, -1, callback);
getSortedSetRangeByScore(key, start, count, min, max, -1, false, callback);
};
function getSortedSetRangeByScore(key, start, count, min, max, sort, callback) {
module.getSortedSetRevRangeByScoreWithScores = function(key, start, count, max, min, callback) {
getSortedSetRangeByScore(key, start, count, min, max, -1, true, callback);
};
function getSortedSetRangeByScore(key, start, count, min, max, sort, withScores, callback) {
if (!key) {
return callback();
}
@@ -159,7 +163,13 @@ module.exports = function(db, module) {
scoreQuery['$lte'] = max;
}
db.collection('objects').find({_key:key, score: scoreQuery}, {fields:{value:1}})
var fields = {_id: 0};
fields['value'] = 1;
if (withScores) {
fields['score'] = 1;
}
db.collection('objects').find({_key:key, score: scoreQuery}, {fields: fields})
.limit(count)
.skip(start)
.sort({score: sort})
@@ -168,9 +178,11 @@ module.exports = function(db, module) {
return callback(err);
}
data = data.map(function(item) {
return item.value;
});
if (!withScores) {
data = data.map(function(item) {
return item.value;
});
}
callback(err, data);
});