Skip to content

Instantly share code, notes, and snippets.

@distracteddev
Created April 15, 2012 04:13
Show Gist options
  • Save distracteddev/2389967 to your computer and use it in GitHub Desktop.
Save distracteddev/2389967 to your computer and use it in GitHub Desktop.
Example of a Resourceful.js Model with a custom MapReduce Filter
var Resourceful = require('resourceful');
var tagFilter = {
map: function (post) {
post.tags.forEach(function (tag) {
emit(tag, 1);
});
},
reduce: function(keys, values) {
return sum(values);
}
};
var options = {
"group":"true",
"raw":"true"
};
var BlogPost = Resourceful.define('blogpost', function () {
this.use('couchdb', {
uri: 'couchdb://zeus.iriscouch.com/blogposts'
//uri: 'couchdb://127.0.0.1:5984/blogposts'
});
this.string('title');
this.string('subTitle');
this.string('body');
this.array('tags');
this.timestamps();
debugger;
this.filter("tagFilter", options, tagFilter);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment