Skip to content
MongoDB generator goodness for node.js
Branch: master
Clone or download
Latest commit a4bed06 Mar 14, 2014
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test docs Dec 18, 2013
.gitignore Initial commit Dec 18, 2013
History.md Release 1.0.0 Mar 14, 2014
Makefile Initial commit Dec 18, 2013
Readme.md docs Dec 18, 2013
index.js Initial commit Dec 18, 2013
package.json Release 1.0.0 Mar 14, 2014

Readme.md

co-monk

MongoDB with generator goodness.

Installation

$ npm install co-monk

Setup

Call wrap() on collections to make them generator friendly:

var monk = require('monk');
var wrap = require('co-monk');
var db = monk('localhost/test');

var users = wrap(db.get('users'));

Example

Simple example:

yield users.remove({});

yield users.insert({ name: 'Tobi', species: 'ferret' });
yield users.insert({ name: 'Loki', species: 'ferret' });
yield users.insert({ name: 'Jane', species: 'ferret' });

var res = yield users.findOne({ name: 'Tobi' });
res.name.should.equal('Tobi');

var res = yield users.find({ species: 'ferret' });
res.should.have.length(3);

Parallel inserts:

yield users.remove({});

yield [
  users.insert({ name: 'Tobi', species: 'ferret' }),
  users.insert({ name: 'Loki', species: 'ferret' }),
  users.insert({ name: 'Jane', species: 'ferret' })
];

var res = yield users.findOne({ name: 'Tobi' });
res.name.should.equal('Tobi');

var res = yield users.find({ species: 'ferret' });
res.should.have.length(3);

License

MIT

You can’t perform that action at this time.