ES6 generator-based MongoDB ODM. It rocks.
Awesome ES6 generator-based MongoDB ODM for Node.js v0.11.x (or newer). Just take a look on its pretty models and beautiful API. Uses monk under the hood.
- Based on ES6 generators, which means no callbacks
- Common, established API you've already used to
- Hooks (before:save, around:create, after:remove, etc)
- Very simple and easy-to-understand implementation
- Fully covered by tests
npm install mongorito --save
Warning: You should have Node.js v0.11.x installed (or newer). Run node with
node --harmony something.js
Note: In order for the following examples to work, you need use something like co to run generators. Another note: If you want to use ES6 classes (like in the following examples), use 6to5. If not, there is an alternative API left from previous versions of Mongorito.
var Mongorito = require'mongorito';var Model = MongoritoModel;// connect to localhost/blogMongoritoconnect'localhost/blog';// define modelclass Post extends Model// create new Post documentvar post =title: 'Node.js with --harmony rocks!'body: 'Long post body'author:name: 'John Doe';// createyield postsave;// update documentpostset'title' 'Post got a new title!';postset'author.name' 'Doe John';// updateyield postsave;// find some postsvar posts;// find posts where body equals "Long post body"posts = yield Postwhere'body' 'Long post body'find;// find posts where author's name equals "John Doe"posts = yield Postwhere'author.name' 'John Doe'find;// Bonus: find posts where title starts with "Node"posts = yield Postwhere'title' /^node/ifind;// disconnectMongoritodisconnect;
To execute tests run:
Mongorito is released under the MIT License.