Reputation: 24886
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 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.
Upvotes: 3
Views: 3008
Reputation: 12165
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.
Upvotes: 4