Skip to content

Node.js based forum software built for the modern web

add withscores

Barış Soner Uşaklıfe80186ddf2b
diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js
index 02ab79533e..d4eb7a8522 100644
--- a/src/database/mongo/sorted.js
+++ b/src/database/mongo/sorted.js
@@ -499,9 +499,13 @@ module.exports = function (db, module) {
module.processSortedSet = function (setKey, processFn, options, callback) {
var done = false;
var ids = [];
+ var project = { _id: 0, value: 1 };
+ if (options.withScores) {
+ project.score = 1;
+ }
var cursor = db.collection('objects').find({ _key: setKey })
.sort({ score: 1 })
- .project({ _id: 0, value: 1 })
+ .project(project)
.batchSize(options.batch);
async.whilst(
@@ -517,7 +521,7 @@ module.exports = function (db, module) {
if (item === null) {
done = true;
} else {
- ids.push(item.value);
+ ids.push(options.withScores ? item : item.value);
}
if (ids.length < options.batch && (!done || ids.length === 0)) {