mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
Allow lex min and max to be inclusive or exclusive.
This commit is contained in:
@@ -596,11 +596,19 @@ module.exports = function (db, module) {
|
|||||||
var query = {_key: key, value: {}};
|
var query = {_key: key, value: {}};
|
||||||
|
|
||||||
if (min !== '-') {
|
if (min !== '-') {
|
||||||
query.value = {$gte: min};
|
if (min.match('(')) {
|
||||||
|
query.value = {$gt: parseInt(min, 10)};
|
||||||
|
} else {
|
||||||
|
query.value = {$gte: parseInt(min, 10)};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (max !== '+') {
|
if (max !== '+') {
|
||||||
query.value = query.value || {};
|
query.value = query.value || {};
|
||||||
query.value.$lte = max;
|
if (max.match('(')) {
|
||||||
|
query.value = {$lt: parseInt(max, 10)};
|
||||||
|
} else {
|
||||||
|
query.value = {$lte: parseInt(max, 10)};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.collection('objects').find(query, {_id: 0, value: 1})
|
db.collection('objects').find(query, {_id: 0, value: 1})
|
||||||
@@ -624,11 +632,19 @@ module.exports = function (db, module) {
|
|||||||
var query = {_key: key};
|
var query = {_key: key};
|
||||||
|
|
||||||
if (min !== '-') {
|
if (min !== '-') {
|
||||||
query.value = {$gte: min};
|
if (min.match('(')) {
|
||||||
|
query.value = {$gt: parseInt(min, 10)};
|
||||||
|
} else {
|
||||||
|
query.value = {$gte: parseInt(min, 10)};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (max !== '+') {
|
if (max !== '+') {
|
||||||
query.value = query.value || {};
|
query.value = query.value || {};
|
||||||
query.value.$lte = max;
|
if (max.match('(')) {
|
||||||
|
query.value = {$lt: parseInt(max, 10)};
|
||||||
|
} else {
|
||||||
|
query.value = {$lte: parseInt(max, 10)};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.collection('objects').remove(query, function (err) {
|
db.collection('objects').remove(query, function (err) {
|
||||||
|
|||||||
@@ -311,20 +311,22 @@ module.exports = function (redisClient, module) {
|
|||||||
function sortedSetLex(method, reverse, key, min, max, start, count, callback) {
|
function sortedSetLex(method, reverse, key, min, max, start, count, callback) {
|
||||||
if (!callback) callback === start;
|
if (!callback) callback === start;
|
||||||
|
|
||||||
|
var minmin, maxmax;
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
if (min !== '+') {
|
minmin = '+';
|
||||||
min = '(' + min;
|
maxmax = '-';
|
||||||
}
|
|
||||||
if (max !== '-') {
|
|
||||||
max = '[' + max;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (min !== '-') {
|
minmin = '-';
|
||||||
min = '[' + min;
|
maxmax = '+';
|
||||||
}
|
}
|
||||||
if (max !== '+') {
|
|
||||||
max = '(' + max;
|
if (min !== minmin) {
|
||||||
}
|
min = '' + min;
|
||||||
|
if (!min.match(/[\[\(]/)) min = '[' + min;
|
||||||
|
}
|
||||||
|
if (max !== maxmax) {
|
||||||
|
max = '' + max;
|
||||||
|
if (!max.match(/[\[\(]/)) max = '[' + max;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count) {
|
if (count) {
|
||||||
|
|||||||
Reference in New Issue
Block a user