@@ -38,24 +38,28 @@ If using the :pipeline:`$limit` stage with any of:
3838- the :pipeline:`$sort` aggregation stage,
3939- the :method:`~cursor.sort()` method, or
4040- the ``sort`` field to the :dbcommand:`findAndModify` command or the
41- :method:`~db.collection.findAndModify()` shell method.
41+ :method:`~db.collection.findAndModify()` shell method,
4242
43- be sure that you are performing a *stable sort* before passing results
44- to the :pipeline:`$limit` stage. A stable sort ensures that the sort
45- order of returned documents remains the same across multiple executions
46- of the same sort; especially important when used with the
47- :pipeline:`$limit` stage.
43+ be sure to include at least one field in your sort that contains
44+ unique values, before passing results to the :pipeline:`$limit` stage.
45+
46+ Sorting on fields that contain duplicate values may return an
47+ inconsistent sort order for those duplicate fields over multiple
48+ executions, especially when the collection is actively receiving writes.
49+
50+ The easiest way to guarantee sort consistency is to include the
51+ ``_id`` field in your sort query.
4852
4953See the following for more information on each:
5054
51- - :ref:`Stable sorting with $sort (aggregation)
52- <sort-aggregation-stable -sorting>`
53- - :ref:`Stable sorting with the sort() method
54- <sort-cursor-stable -sorting>`
55- - :ref:`Stable sorting with the findAndModify command
56- <findandmodify-command-stable -sorting>`
57- - :ref:`Stable sorting with the findAndModify() method
58- <findandmodify-method-stable -sorting>`
55+ - :ref:`Consistent sorting with $sort (aggregation)
56+ <sort-aggregation-consistent -sorting>`
57+ - :ref:`Consistent sorting with the sort() shell method
58+ <sort-cursor-consistent -sorting>`
59+ - :ref:`Consistent sorting with the findAndModify command
60+ <findandmodify-command-consistent -sorting>`
61+ - :ref:`Consistent sorting with the findAndModify() shell method
62+ <findandmodify-method-consistent -sorting>`
5963
6064Example
6165-------
0 commit comments