mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
addl lex commands for mongo
This commit is contained in:
@@ -579,7 +579,22 @@ module.exports = function (db, module) {
|
||||
};
|
||||
|
||||
module.getSortedSetRangeByLex = function (key, min, max, start, count, callback) {
|
||||
var query = {_key: key};
|
||||
sortedSetLex(key, min, max, 1, start, count, callback);
|
||||
};
|
||||
|
||||
module.getSortedSetRevRangeByLex = function (key, min, max, start, count, callback) {
|
||||
sortedSetLex(key, min, max, -1, start, count, callback);
|
||||
};
|
||||
|
||||
module.sortedSetLexCount = function (key, min, max, callback) {
|
||||
sortedSetLex(key, min, max, 1, 0, 0, function (err, data) {
|
||||
callback(err, data ? data.length : null);
|
||||
});
|
||||
};
|
||||
|
||||
function sortedSetLex(method, sort, key, min, max, start, count, callback) {
|
||||
var query = {_key: key, value: {}};
|
||||
|
||||
if (min !== '-') {
|
||||
query.value = {$gte: min};
|
||||
}
|
||||
@@ -587,8 +602,9 @@ module.exports = function (db, module) {
|
||||
query.value = query.value || {};
|
||||
query.value.$lte = max;
|
||||
}
|
||||
|
||||
db.collection('objects').find(query, {_id: 0, value: 1})
|
||||
.sort({value: 1})
|
||||
.sort({value: sort})
|
||||
.skip(start)
|
||||
.limit(count === -1 ? 0 : count)
|
||||
.toArray(function (err, data) {
|
||||
@@ -600,6 +616,24 @@ module.exports = function (db, module) {
|
||||
});
|
||||
callback(err, data);
|
||||
});
|
||||
}
|
||||
|
||||
module.sortedSetRemoveRangeByLex = function (key, min, max, callback) {
|
||||
callback = callback || helpers.noop;
|
||||
|
||||
var query = {_key: key};
|
||||
|
||||
if (min !== '-') {
|
||||
query.value = {$gte: min};
|
||||
}
|
||||
if (max !== '+') {
|
||||
query.value = query.value || {};
|
||||
query.value.$lte = max;
|
||||
}
|
||||
|
||||
db.collection('objects').remove(query, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.processSortedSet = function (setKey, process, batch, callback) {
|
||||
|
||||
Reference in New Issue
Block a user