hmarr/mongoengine — Issue #427: order_by() on DecimalField does not work as expected 
Author: e-dard
Created: 2012-02-04 13:42:05+00:00
State: open

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:

```python
.. 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.
```