Skip to content

Commit d9078e5

Browse files
author
Chris Cho
authored
DOCSP-29523: fix skip and limit example (#379)
* DOCSP-29523: Fix the skip and limit example
1 parent 5fd835d commit d9078e5

File tree

1 file changed

+10
-7
lines changed
  • source/fundamentals/crud/read-operations

1 file changed

+10
-7
lines changed

source/fundamentals/crud/read-operations/limit.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ documents that a read operation can return. If there are not enough documents
2424
to reach the specified limit, it can return a smaller number.
2525
If you use ``limit()`` with the ``skip()`` instance method, the skip applies
2626
first and the limit only applies to the documents left over after
27-
the skip. For more information on the ``skip()`` method, see our
28-
:doc:`guide on Skipping Returned Documents </fundamentals/crud/read-operations/skip/>`.
27+
the skip. For more information on the ``skip()`` method, see our
28+
:doc:`guide on Skipping Returned Documents </fundamentals/crud/read-operations/skip/>`.
2929

3030
The following examples demonstrate, respectively, how to insert data into
3131
a collection, how to use ``limit()`` to restrict the number of returned documents,
@@ -64,9 +64,13 @@ longest books. It first matches all the documents with the query, then sorts on
6464
books with shorter lengths. Lastly, it limits the return value to ``3`` documents:
6565

6666
.. code-block:: java
67-
:emphasize-lines: 6
67+
:emphasize-lines: 10
6868

69-
import com.mongodb.client.model.Sorts;
69+
import com.mongodb.client.*;
70+
import org.bson.Document;
71+
import static com.mongodb.client.model.Sorts.descending;
72+
73+
// ...
7074

7175
// define a cursor that will return the first 3 sorted items
7276
MongoCursor<Document> cursor = collection.find()
@@ -109,14 +113,13 @@ Combining Skip and Limit
109113
------------------------
110114

111115
To see the next three longest books, append the ``skip()`` method to your
112-
``find()`` call. The integer argument passed to ``skip()`` will determine
113-
how many documents the find operation returns:
116+
``find()`` call as shown in the following code example:
114117

115118
.. code-block:: java
116119
:emphasize-lines: 3, 4
117120

118121
MongoCursor<Document> cursor = collection.find()
119-
.sort(ascending("length"))
122+
.sort(descending("length"))
120123
.limit(3)
121124
.skip(3)
122125
.iterator();

0 commit comments

Comments
 (0)