add withscores

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 6ae5d7ccae
commit fe80186ddf

@ -499,9 +499,13 @@ module.exports = function (db, module) {
module.processSortedSet = function (setKey, processFn, options, callback) { module.processSortedSet = function (setKey, processFn, options, callback) {
var done = false; var done = false;
var ids = []; var ids = [];
var project = { _id: 0, value: 1 };
if (options.withScores) {
project.score = 1;
}
var cursor = db.collection('objects').find({ _key: setKey }) var cursor = db.collection('objects').find({ _key: setKey })
.sort({ score: 1 }) .sort({ score: 1 })
.project({ _id: 0, value: 1 }) .project(project)
.batchSize(options.batch); .batchSize(options.batch);
async.whilst( async.whilst(
@ -517,7 +521,7 @@ module.exports = function (db, module) {
if (item === null) { if (item === null) {
done = true; done = true;
} else { } else {
ids.push(item.value); ids.push(options.withScores ? item : item.value);
} }
if (ids.length < options.batch && (!done || ids.length === 0)) { if (ids.length < options.batch && (!done || ids.length === 0)) {

Loading…
Cancel
Save