You need to use mongodb aggregation framework to find the users who got the more than 5 reports
In mongo shell
db.reports.aggregate(
// Group by user_id
{$group:{_id:'$user_id',count:{$sum:1},
// Add the fields to result set along with grouped result
name:{$addToSet:'$any_field_you_need_to_return'}}},
// And return only the users who got greater than 5 reports
{$match:{count:{$gt:5}}})
Update
Aggregate
only introduced in moped v1.3
. You need to make a change in your gemfile to install the latest moped and run bundle install
gem 'moped', :git=>'https://github.com/mongoid/moped.git', :branch => "master"
And you can use aggregate like
Reports.collection.aggregate(
{'$group' => {'_id' => '$user_id','count' => {'$sum' => 1},
'name' => {'$addToSet' => '$any_field_you_need_to_return'}}},
{'$match' => {'count' => {'$gt' => 5 }}})