Skip to content

Instantly share code, notes, and snippets.

@sunny0425
Created December 4, 2012 10:30
Show Gist options
  • Save sunny0425/4202491 to your computer and use it in GitHub Desktop.
Save sunny0425/4202491 to your computer and use it in GitHub Desktop.
run mongo script in rails console
$ mongo
> db.view_logs.aggregate(
{$match : {created_at : {$gt : new Date( "12/01/2012" )}}},
{ $group : {
_id : "$loggable_id",
cc : { $sum : 1 },
}},
{ $sort : { cc : -1 }},
{ $limit : 5 }
);
$ rails console
> s = "db.view_logs.aggregate({ \"$group\" :{\"_id\": \"$loggable_id\", \"cc\" : {\"$sum\" : 1}}})"
>Mongoid.master.eval(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment