Skip to content

Commit a07877c

Browse files
committed
NR feedback
1 parent 662f332 commit a07877c

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

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

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Skip Returned Results
2020
Overview
2121
--------
2222

23-
In this guide, you can learn how to use the {+driver-long+} to specify the
24-
number of documents to skip in a read operation.
23+
In this guide, you can learn how to use the {+driver-long+} to perform a read
24+
operation that skips a specified number of documents when returning results.
2525

2626
Sample Data for Examples
2727
------------------------
@@ -44,12 +44,16 @@ collection:
4444
:language: rust
4545
:dedent:
4646

47-
Skip
48-
----
47+
Skip Documents
48+
--------------
4949

50-
To skip results retrieved by a query, you can chain the ``skip()`` method to the
51-
``find()`` method. Alternatively, if you are setting and reusing options for
52-
your query, you can use the ``skip()`` method of the ``FindOptions`` struct.
50+
This section describes how to skip results retrieved by a query in the following ways:
51+
52+
- :ref:`skip() method <rust-skip-method>`: Chain the ``skip()`` method to the
53+
``find()`` method
54+
- :ref:`FindOptions::skip() method <rust-findoptions-skip>`: Use the ``skip()``
55+
method of the ``FindOptions`` struct if you are setting and reusing options
56+
for your query
5357

5458
If the number of skipped documents exceeds the number of matched documents for a
5559
query, then that query returns no documents.
@@ -59,12 +63,18 @@ fields. To avoid skipping random documents, use the ``sort()`` method to sort
5963
documents on a field with a unique value before setting a skip option. To learn
6064
more, see the :ref:`rust-sort-guide` guide.
6165

62-
Example
63-
~~~~~~~
66+
.. _rust-skip-method:
67+
68+
skip() Method Example
69+
~~~~~~~~~~~~~~~~~~~~~~
6470

65-
The following example performs a ``find()`` operation with the following behavior:
71+
The ``skip()`` method takes an integer that specifies the number of documents to
72+
omit from the beginning of the result set. You can chain the ``skip()`` method
73+
to the ``find()`` method to skip documents.
6674

67-
- Sorts the results in ascending order on the ``author`` field
75+
This example runs a ``find()`` operation that performs the following actions:
76+
77+
- Sorts the results in ascending order of their ``author`` field values
6878
- Skips the first two documents
6979
- Returns the remaining documents
7080

@@ -84,12 +94,17 @@ The following example performs a ``find()`` operation with the following behavio
8494
Book { name: "A Dance with Dragons", author: "Martin", length: 1104 }
8595
Book { name: "Atlas Shrugged", author: "Rand", length: 1088 }
8696

97+
.. _rust-findoptions-skip:
98+
8799
Options Example
88100
~~~~~~~~~~~~~~~
89101

90-
Alternatively, you can use the ``skip()`` method of the ``FindOptions`` struct.
91-
The following example performs a ``find()`` operation with the following
92-
behavior:
102+
Alternatively, you can set the ``skip`` field of the ``FindOptions`` struct by
103+
using the ``skip()`` setter method. Then, chain the ``with_options()`` method to
104+
the ``find()`` method and pass your ``FindOptions`` struct as a parameter to the
105+
``with_options()`` method.
106+
107+
This example runs a ``find()`` operation that performs the following actions:
93108

94109
- Sorts the results in descending order on the ``name`` field
95110
- Skips the first document
@@ -113,16 +128,15 @@ behavior:
113128
Book { name: "Atlas Shrugged", author: "Rand", length: 1088 }
114129

115130
Aggregation
116-
-----------
131+
~~~~~~~~~~~
117132

118133
You can use the ``$skip`` stage in an aggregation pipeline to skip documents. To
119134
learn more, see the :ref:`rust-aggregation` guide.
120135

121136
Example
122137
~~~~~~~
123138

124-
The following example uses the ``aggregate()`` method to perform an aggregation
125-
operation with the following behavior:
139+
This example runs an aggregation pipeline that performs the following actions:
126140

127141
- Sorts the results in ascending order on the ``author`` field
128142
- Skips the first document
@@ -148,7 +162,7 @@ operation with the following behavior:
148162
Additional Information
149163
----------------------
150164

151-
To learn more about the operations mentioned in this guide, see the following:
165+
To learn more about the operations mentioned in this guide, see the following guides:
152166

153167
- :ref:`rust-query-guide`
154168
- :ref:`rust-retrieve-guide`
@@ -161,7 +175,7 @@ API Documentation
161175
~~~~~~~~~~~~~~~~~
162176

163177
To learn more about any of the methods or types discussed in this guide, see the
164-
following API Documentation:
178+
following API documentation:
165179

166180
- `find() <{+api+}/struct.Collection.html#method.find>`__
167181
- `FindOptions <{+api+}/options/struct.FindOptions.html>`__

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ API Documentation
194194
~~~~~~~~~~~~~~~~~
195195

196196
To learn more about any of the methods or types discussed in this guide, see the
197-
following API Documentation:
197+
following API documentation:
198198

199199
- `find() <{+api+}/struct.Collection.html#method.find>`__
200200
- `FindOptions <{+api+}/options/struct.FindOptions.html>`__

source/includes/fundamentals/code-snippets/crud/skip.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ async fn main() -> mongodb::error::Result<()> {
4949
my_coll.insert_many(books).await?;
5050
// end-sample-data
5151

52+
// Retrieves documents in the collection, sorts results by their "author" field
53+
// values, and skips the first two results.
5254
// start-skip-example
5355
let mut cursor = my_coll
5456
.find(doc! {})
@@ -60,6 +62,9 @@ async fn main() -> mongodb::error::Result<()> {
6062
}
6163
// end-skip-example
6264

65+
// Sets the values for the `FindOptions` struct to sort results by their "name"
66+
// field values, skip the first two results, and limit the results to two
67+
// documents.
6368
// start-options-skip-example
6469
let find_options = FindOptions::builder()
6570
.sort(doc! { "name": -1 })
@@ -74,6 +79,8 @@ async fn main() -> mongodb::error::Result<()> {
7479
}
7580
// end-options-skip-example
7681

82+
// Retrieves documents in the collection, sorts results by their "author" field,
83+
// then skips the first two results in an aggregation pipeline.
7784
// start-aggregation-example
7885
let pipeline = vec![
7986
doc! { "$match": {} },

0 commit comments

Comments
 (0)