Skip to content

Commit 1170de1

Browse files
committed
added explicit doc for order_by #2117
1 parent 332bd76 commit 1170de1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

docs/guide/mongomock.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ or with an alias:
2121
conn = get_connection('testdb')
2222
2323
Example of test file:
24-
--------
24+
---------------------
2525
.. code-block:: python
2626
2727
import unittest

docs/guide/querying.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ keyword argument::
222222

223223
.. versionadded:: 0.4
224224

225+
Sorting/Ordering results
226+
========================
227+
It is possible to order the results by 1 or more keys using :meth:`~mongoengine.queryset.QuerySet.order_by`.
228+
The order may be specified by prepending each of the keys by "+" or "-". Ascending order is assumed if there's no prefix.::
229+
230+
# Order by ascending date
231+
blogs = BlogPost.objects().order_by('date') # equivalent to .order_by('+date')
232+
233+
# Order by ascending date first, then descending title
234+
blogs = BlogPost.objects().order_by('+date', '-title')
235+
236+
225237
Limiting and skipping results
226238
=============================
227239
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`::
585597
['database', 'mongodb']
586598

587599
From MongoDB version 2.6, push operator supports $position value which allows
588-
to push values with index.
600+
to push values with index::
601+
589602
>>> post = BlogPost(title="Test", tags=["mongo"])
590603
>>> post.save()
591604
>>> post.update(push__tags__0=["database", "code"])

0 commit comments

Comments
 (0)