Skip to content

Instantly share code, notes, and snippets.

@superp
Created July 6, 2011 13:57
Show Gist options
  • Save superp/1067281 to your computer and use it in GitHub Desktop.
Save superp/1067281 to your computer and use it in GitHub Desktop.
Group by example in MongoMapper
class Tweet
include MongoMapper::Document
key :id_str, String
key :from_user_id, Integer
belongs_to :track_item
def self.grouped_by(column, options = {})
map_function = "function() { emit( this.#{column}, 1); }"
# put your logic here (not needed in my case)
reduce_function = %Q( function(key, values) {
return true;
})
collection.map_reduce(map_function, reduce_function, options)
end
end
Tweet.grouped_by(:from_user_id, :query => {:track_item_id => track_item.id}).find().count
@ringe
Copy link

ringe commented Mar 17, 2014

I get the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment