I want groups of person which is ordered by age
I tried something like this
Person.only(:name).asc(:age).group
But didn't ordered by age.
How can I do it?
I'm using mongoid beta 19开发者_StackOverflow.
If I remember correctly, once you have called
Person.only(:name)
Mongoid basically considers the collection to only have that field so once you have tried to sort by age, there is no age field to sort by so it does nothing.
Try
Person.asc(:age).only(:name).group
Or possibily
Person.asc(:age).only([:name, :age]).group
精彩评论