Created
December 3, 2012 08:40
-
-
Save sunny0425/4193689 to your computer and use it in GitHub Desktop.
user group in mongoid
This file contains hidden or 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
results = Letter.collection.group({ | |
:key => 'author_id', | |
:initial => {:count => 0}, | |
:reduce => "function(x, y) { y.count++;}" | |
}) | |
ViewLog.only(:loggable_id).aggregate | |
=> [{"loggable_id"=>BSON::ObjectId('5062678e0a217501dd000015'), "count"=>2.0}, | |
{"loggable_id"=>BSON::ObjectId('506267e00a217501dd000084'), "count"=>2.0}, | |
{"loggable_id"=>BSON::ObjectId('508fa73c0a21750e74000051'), "count"=>25.0}, | |
{"loggable_id"=>BSON::ObjectId('505bec4e0a21750383000003'), "count"=>1.0}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment