Cabinet
Brainless Key/Value storage for MongoDB
Cabinet
is a tiny module built on top of Cellar (itself built on top of Mongoose) for a simple Key/Value store.
Installation
Through NPM
$ npm install cabinetkv
or using Git
$ git clone git://github.com/treygriffith/cabinet.git node_modules/cabinetkv/
API/How to Use
Instantiate Cabinet with a collection name, and mongoDB details or a Mongoose instance
Cabinet = ;// with Mongoose instancevar mongoose = ;var mongoUrl = 'mongodb://' + dbuser + ':' + dbpass + '@' + dbhost + ':' + dbport + '/' + dbname;mongoose;var cabinet = 'mykvstore' mongoose maxAge:3// with mongoDB details (maxAge of -1 stores docs forever)var cabinet = 'mykvstore' user:dbuser pass:dbpass host:dbhost port:dbport name:dbname maxAge:-1;
Cabinet exposes 2 methods:
set
- Store a value
// Store a value with a specific keycabinet;// Store a value with a randomly generated keycabinet;2 `get` - Retrieve a value``` javascriptcabinet.get('mykey', function(err, val) {if(err) {console.error(err);return;}console.log(val); // prints 'myvalue'});