added explicit doc for order_by #2117

This commit is contained in:
Bastien Gérard 2019-12-20 23:16:29 +01:00
parent 332bd767d4
commit 1170de1e8e
2 changed files with 15 additions and 2 deletions

View File

@ -21,7 +21,7 @@ or with an alias:
conn = get_connection('testdb')
Example of test file:
--------
---------------------
.. code-block:: python
import unittest

View File

@ -222,6 +222,18 @@ keyword argument::
.. versionadded:: 0.4
Sorting/Ordering results
========================
It is possible to order the results by 1 or more keys using :meth:`~mongoengine.queryset.QuerySet.order_by`.
The order may be specified by prepending each of the keys by "+" or "-". Ascending order is assumed if there's no prefix.::
# Order by ascending date
blogs = BlogPost.objects().order_by('date') # equivalent to .order_by('+date')
# Order by ascending date first, then descending title
blogs = BlogPost.objects().order_by('+date', '-title')
Limiting and skipping results
=============================
Just as with traditional ORMs, you may limit the number of results returned or
@ -585,7 +597,8 @@ cannot use the `$` syntax in keyword arguments it has been mapped to `S`::
['database', 'mongodb']
From MongoDB version 2.6, push operator supports $position value which allows
to push values with index.
to push values with index::
>>> post = BlogPost(title="Test", tags=["mongo"])
>>> post.save()
>>> post.update(push__tags__0=["database", "code"])