开发者

How to make Mongoid order properly?

I've been trying to figure out why Mongoid thinks 387 is smaller than 67. I have two records and the row with 67 is appearing above the row with 387 every time. My query is simple

Building.desc(:violations)

I have also tried order_by() and it's the same story.

Edit:

I now changed the field开发者_StackOverflow中文版 type to Integer on some fields, and to BigDecimal for other fields where the numbers are greater -- especially currency figures. That fixed the Integer fields, but BigDecimal fields are still not sorting properly.


Check the data type on the fields. In MongoDB, it can be pretty easy to store something as a string when you really meant to store it as a numeric value of some sort.

More information and examples about data types available from the MongoDB documentation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜