开发者

Ordering and grouping in mongoid

开发者 https://www.devze.com 2023-02-05 05:04 出处:网络
I want groups of person which is ordered by age I tried something like this Person.only(:name).asc(:age).group

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
0

精彩评论

暂无评论...
验证码 换一张
取 消