Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (49 sloc) 1.9 KB


On-the-fly processing framework for Node.js and MongoDB.


npm install nettle


A store provides a simple interface to the GridFS entities in a MongoDB database. It provides basic put, get, and delete operations and allows the data to be arbitrarily processed.

var nettle = require('nettle');
var store ={ db: 'nettle' });

Optionally specify host, port and collection prefix (defaults to 'fs') when creating a store.

Putting an entity into the store:

store.put(new Buffer('foo'), function(err, doc) {

Getting an entity out of the store:

store.get(id, function(err, buffer) {

// -> 'foo'

Removing an entity from the store:

store.delete(id, function(err) {


A processor defines an operation to be performed on entities in a store. Each processor is referenced by a unique name that is specified at its creation. An example string processor might look something like this:

store.processor('reversed', function(buffer, callback) {
    var reversed = buffer.toString().split('').reverse().join('');
    callback(null, new Buffer(reversed));

One can then retrieve processed entities by passing the processor name to get:

store.get(id, 'reversed', function(err, buffer) {

// -> 'oof'

Note that processed entities are cached internally. The processor function will only be called when the given id and processor name are not found in the cache. One can also explicitly force an entity to be processed:

store.process(id, 'reversed', function(err, buffer) {

// -> 'oof'

When deleting an entity, its associated cache will be deleted as well.