If I remember correctly, as soon as you called
Person.only(:name)
Mongoid basically considers the collection only for this field, therefore, as soon as you try to sort by age, there is no age field to sort, so it does nothing.
Try
Person.asc(:age).only(:name).group
Or maybe
Person.asc(:age).only([:name, :age]).group
source share