Created
July 6, 2011 13:57
-
-
Save superp/1067281 to your computer and use it in GitHub Desktop.
Group by example in MongoMapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
undefined method `last' for nil:NilClass
I get this error when I try and run map reduce, any idea why?
I get the same error.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get what you're doing there but I get:
The error occurred while evaluating nil.last
/Users/mmitchell/.rbenv/versions/ree-1.8.7-2011.03/lib/ruby/gems/1.8/gems/mongo-1.8.2/lib/mongo/util/support.rb:83:in `secondary_ok?'
Any ideas on this?
Many thanks