How to order Mongoid correctly?

I am trying to understand why Mongoid thinks 387 is less than 67. I have two entries and line 67 appears above line 387 each time. My request is simple

Building.desc(:violations)

I also tried order_by(), and this is the same story.

Edit:

Now I have changed the type of the field to Integer for some fields and to BigDecimal for other fields, where the numbers are larger - especially the currency digits. This fixed the Integer fields, but BigDecimal fields are still not sorted properly.

+3
source share
1 answer

Check the data type in the fields. In MongoDB, it's pretty easy to store something as a string when you really wanted to save it as a numeric value of some type.

, MongoDB.

+4

Source: https://habr.com/ru/post/1785686/


All Articles