So I have the following group by SQL

```
select count(*) as NO_OF_MSGS,FROM_USER,PROFILE_IMG,MSG from MESSAGES group by FROM_USER order by NO_OF_MSGS desc,DATE_SENT limit ?,?

```

How can I replicate this group by in MongoDB. I came across this excellent write up - <http://kylebanker.com/blog/2009/11/mongodb-count-group/>

This shows how you can use group by in Mongo, but it **does not** talk about how to implement `order by` and `limit` inside a group.

Also it seems Mongoid does not provide support for `group` function, anyone know if its any different?