Skip to content

Commit

Permalink
Merge pull request #73 from jockster/master
Browse files Browse the repository at this point in the history
Updated readme
  • Loading branch information
fengmk2 committed Oct 10, 2012
2 parents 5e83b20 + ce12f8b commit 5af5fb7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Readme.md
Expand Up @@ -172,6 +172,10 @@ It is very useful if you want to use MVC patterns with nodejs and mongodb.
You can also invoke collection by properties after bind,
it could simplfy your `require`.

To keep your code in line with DRY principles, it's possible to create your own
data layer by for example, setting up your own validators and/or default values
inside the MVC methods as shown below in the config example

```js
db.bind('posts', {
findTop10 : function (fn) {
Expand All @@ -180,8 +184,26 @@ db.bind('posts', {
removeTagWith : function (tag, fn) {
this.remove({tags:tag},fn);
}
}
});

db.bind('settings', {

getAll: function(user, fn) {

this.find({user: user}).toArray(function(err, settings) {

// We want to set a default currency from within our app instead of storing it
// for every user
settings.currency = (typeof settings.currency !== "undefined") ? settings.currency : 'USD';

fn(err, settings);

});
}
});


db.bind('comments');

db.collection('posts').removeTagWith('delete', function (err, replies) {
Expand Down

0 comments on commit 5af5fb7

Please sign in to comment.