Skip to content

Node.js based forum software built for the modern web

sortedSetCount fix for +inf/-inf

barisusakli0a534b20e32b
diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js
index 603b1ab770..d21d7a616b 100644
--- a/src/database/mongo/sorted.js
+++ b/src/database/mongo/sorted.js
@@ -204,7 +204,14 @@ module.exports = function(db, module) {
if (!key) {
return callback();
}
- db.collection('objects').count({_key: key, score: {$gte: min, $lte: max}}, function(err, count) {
+ var scoreQuery = {};
+ if (min !== '-inf') {
+ scoreQuery.$gte = min;
+ }
+ if (max !== '+inf') {
+ scoreQuery.$lte = max;
+ }
+ db.collection('objects').count({_key: key, score: scoreQuery}, function(err, count) {
callback(err, count ? count : 0);
});
};
diff --git a/tests/database/sorted.js b/tests/database/sorted.js
index c00bd2a392..e202b5738f 100644
--- a/tests/database/sorted.js
+++ b/tests/database/sorted.js
@@ -141,7 +141,7 @@ describe('Sorted Set methods', function() {
describe('getSortedSetRevRangeByScoreWithScores()', function() {
it('should get count elements with score between max min sorted by score highest to lowest', function(done) {
- db.getSortedSetRevRangeByScoreWithScores('sorted2', 0, -1, '+inf', 1, function(err, values) {
+ db.getSortedSetRevRangeByScoreWithScores('sorted2', 0, -1, '+inf', 2, function(err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}]);