Skip to content

Instantly share code, notes, and snippets.

@psychobunny
Created July 28, 2014 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psychobunny/bdef7d48de43e2e1e451 to your computer and use it in GitHub Desktop.
Save psychobunny/bdef7d48de43e2e1e451 to your computer and use it in GitHub Desktop.
redis-like LTRIM for mongodb
module.listLTrim = function(key, start, stop, callback) {
module.getListRange(key, start, stop, function(err, value) {
if(err) {
if(typeof callback === 'function') {
return callback(err);
}
return;
}
db.collection('objects').update({_key: key }, {$set: value}, function(err, result) {
if(typeof callback === 'function') {
callback(err, (value && value.length) ? value[0] : null);
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment