开发者

Ordering and grouping in mongoid

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜