From 6bed65dde6a7a77e775016c4b350312cd49259e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 19 Apr 2023 17:16:45 -0400 Subject: [PATCH] fix: numeric strings in mongo (#11498) --- src/database/mongo/sorted.js | 6 +++--- test/database/sorted.js | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js index 16bc5f2154..9dcb1aa2d3 100644 --- a/src/database/mongo/sorted.js +++ b/src/database/mongo/sorted.js @@ -49,15 +49,15 @@ module.exports = function (module) { } if (min !== '-inf') { - query.score = { $gte: min }; + query.score = { $gte: parseFloat(min) }; } if (max !== '+inf') { query.score = query.score || {}; - query.score.$lte = max; + query.score.$lte = parseFloat(max); } if (max === min) { - query.score = max; + query.score = parseFloat(max); } const fields = { _id: 0, _key: 0 }; diff --git a/test/database/sorted.js b/test/database/sorted.js index a5262a5394..7b99edd19d 100644 --- a/test/database/sorted.js +++ b/test/database/sorted.js @@ -452,6 +452,12 @@ describe('Sorted Set methods', () => { }); }); }); + + it('should return elements if min/max are numeric strings', async () => { + await db.sortedSetAdd('zsetstringminmax', [1, 2, 3, 4, 5], ['value1', 'value2', 'value3', 'value4', 'value5']); + const results = await db.getSortedSetRevRangeByScore('zsetstringminmax', 0, -1, '3', '3'); + assert.deepStrictEqual(results, ['value3']); + }); }); describe('getSortedSetRevRangeByScore()', () => {