mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

order_by() on DecimalField does not work as expected

Open e-dard opened this issue 13 years ago • 0 comments

I expected DecimalField to behave like a floating point number, rather than a string, with respect to it's natural ordering.

In Mongoengine because DecimalFields are actually stored as strings, they are ordered lexicographically, which creates problems when you want to retrieve their parent documents according to the DecimalFields' numerical values.

I'm assuming that this is more of an architectural issue and not a bug, but given I spent 1-2 hours pinning down what was wrong with my application I would like to raise an issue suggesting that the MongoEngine docs are amended with a note under DecimalField explaining that functions such as order_by may not work as expected.

How about the following in the doc string of DecimalField:

.. note::
             Values in DecimalFields are stored as unicode strings. 
             Therefore, operations involving comparisons, such as 
             :meth:`~mongoengine.queryset.order_by` will use  
             lexicographical comparisons when applied to 
             DecimalFields.

e-dard avatar Feb 04 '12 13:02 e-dard