You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB
JavaScript

'use strict';
module.exports = function (db, module) {
var helpers = module.helpers.mongo;
module.sortedSetRemove = function (key, value, callback) {
function done(err) {
callback(err);
}
callback = callback || helpers.noop;
if (!key) {
return callback();
}
if (Array.isArray(value)) {
value = value.map(helpers.valueToString);
db.collection('objects').remove({_key: key, value: {$in: value}}, done);
} else {
value = helpers.valueToString(value);
db.collection('objects').remove({_key: key, value: value}, done);
}
};
module.sortedSetsRemove = function (keys, value, callback) {
callback = callback || helpers.noop;
if (!Array.isArray(keys) || !keys.length) {
return callback();
}
value = helpers.valueToString(value);
db.collection('objects').remove({_key: {$in: keys}, value: value}, function (err) {
callback(err);
});
};
module.sortedSetsRemoveRangeByScore = function (keys, min, max, callback) {
callback = callback || helpers.noop;
if (!Array.isArray(keys) || !keys.length) {
return callback();
}
var query = {_key: {$in: keys}};
if (min !== '-inf') {
query.score = {$gte: min};
}
if (max !== '+inf') {
query.score = query.score || {};
query.score.$lte = max;
}
db.collection('objects').remove(query, function (err) {
callback(err);
});
};
};