Skip to content

Instantly share code, notes, and snippets.

@kainlite
Created February 24, 2012 17:45
Show Gist options
  • Save kainlite/1902333 to your computer and use it in GitHub Desktop.
Save kainlite/1902333 to your computer and use it in GitHub Desktop.
Mongo Assertion Error With MapReduce
class SomeDocument
include MongoMapper::Document
# Other stuff...
def self.tag_cloud_map
<<-MAP
function() {
this.tags.forEach(function(tag) {
emit(tag, 1);
});
}
MAP
end
def self.tag_cloud_reduce
<<-REDUCE
function(key, values) {
var count = 0;
values.forEach(function(value) {
count += 1;
});
return count;
}
REDUCE
end
def self.tag_cloud_build(opts)
self.collection.map_reduce(self.tag_cloud_map, self.tag_cloud_reduce, opts)
end
def self.tag_cloud(opts={})
opts.merge({
:out => {:inline => true},
:raw => true
})
self.tag_cloud_build(opts).find()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment