@@ -110,6 +110,29 @@ longest books:
110
110
You can combine ``skip()`` and ``limit()`` in this way to implement paging for your
111
111
collection, returning only small subsets of the collection at one time.
112
112
113
+ .. note::
114
+
115
+ In order to ensure stable sorts across multiple queries, you must sort
116
+ using a unique key (such as ``_id``). Otherwise, a call to ``skip()``
117
+ and ``limit()`` may produce unpredictable results when combined with
118
+ ``sort()``.
119
+
120
+ For example, consider the following data:
121
+
122
+ .. code_block:: java
123
+
124
+ { type: "computer", data: "1", serial_no: 235235 }
125
+ { type: "computer", data: "2", serial_no: 235237 }
126
+ { type: "computer", data: "3", serial_no: 235239 }
127
+ { type: "computer", data: "4", serial_no: 235241 }
128
+
129
+ If you sorted by ``type`` alone, ``sort()`` does not guarantee the same order
130
+ upon return. Appending ``skip()`` and ``limit()`` to the ``sort()``
131
+ could return different documents for different queries. In this case, sorting
132
+ by ``data`` or ``serial_no`` would guarantee a stable sort, as both are unique keys.
133
+
134
+
135
+
113
136
For additional information on the classes and methods mentioned on this
114
137
page, see the following API documentation:
115
138
0 commit comments