Skip to content

Node.js based forum software built for the modern web

fix -inf +inf

Barış Soner Uşaklıea9fccbf2afe
diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js
index 565189dd8f..5b06e22cfb 100644
--- a/src/database/mongo/sorted.js
+++ b/src/database/mongo/sorted.js
@@ -204,14 +204,17 @@ module.exports = function(db, module) {
if (!key) {
return callback();
}
- var scoreQuery = {};
+
+ var query = {_key: key};
if (min !== '-inf') {
- scoreQuery.$gte = min;
+ query.score = {$gte: min};
}
if (max !== '+inf') {
- scoreQuery.$lte = max;
+ query.score = query.score || {};
+ query.score.$lte = max;
}
- db.collection('objects').count({_key: key, score: scoreQuery}, function(err, count) {
+
+ db.collection('objects').count(query, function(err, count) {
callback(err, count ? count : 0);
});
};
diff --git a/tests/database/sorted.js b/tests/database/sorted.js
index 68e6f587da..9e92a4c388 100644
--- a/tests/database/sorted.js
+++ b/tests/database/sorted.js
@@ -172,6 +172,13 @@ describe('Sorted Set methods', function() {
assert.equal(count, 2);
done();
});
+
+ db.sortedSetCount('sortedSetTest1', '-inf', '+inf', function(err, count) {
+ assert.equal(err, null);
+ assert.equal(arguments.length, 2);
+ assert.equal(count, 3);
+ done();
+ });
});
});