Skip to content

Commit 942dc13

Browse files
committed
updates for version
1 parent 1c56d07 commit 942dc13

File tree

3 files changed

+15
-68
lines changed

3 files changed

+15
-68
lines changed

source/fundamentals/crud/read-operations.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Read Operations
1313
Open Change Streams </fundamentals/crud/read-operations/change-streams>
1414
Search Text </fundamentals/crud/read-operations/text-search>
1515
Sort Data </fundamentals/crud/read-operations/sort>
16+
Skip Results </fundamentals/crud/read-operations/skip>
1617

1718
..
1819
/fundamentals/crud/read-operations/count

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

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ Skip Documents
5050
You can skip results retrieved by a query, or you can skip results within an
5151
aggregation pipeline.
5252

53-
This section describes how to skip results in the following ways:
54-
55-
- :ref:`skip() method <rust-skip-method>`: Chain the ``skip()`` method to the
56-
``find()`` method
57-
- :ref:`FindOptions struct <rust-findoptions-skip>`: Use the ``skip()`` option
58-
builder method to configure a ``FindOptions`` struct
59-
- :ref:`Aggregation pipleline <rust-aggregation-skip>`: Create a pipeline that uses the ``$skip`` stage
60-
6153
If the number of skipped documents exceeds the number of matched documents for a
6254
query, then that query returns no documents.
6355

@@ -66,14 +58,14 @@ fields. To avoid skipping random documents, use the ``sort()`` method to sort
6658
documents on a field with a unique value before setting a skip option. To learn
6759
more, see the :ref:`rust-sort-guide` guide.
6860

69-
.. _rust-skip-method:
61+
.. _rust-skip-example:
7062

71-
skip() Method Example
72-
~~~~~~~~~~~~~~~~~~~~~~
63+
Query Results Example
64+
~~~~~~~~~~~~~~~~~~~~~
7365

74-
To skip documents, you can chain the ``skip()`` method to the ``find()`` method.
75-
The ``skip()`` method takes an integer that specifies the number of documents to
76-
omit from the beginning of the result set.
66+
To skip documents, you can initialize a ``FindOptions`` instance and specify the
67+
number of documents you want to skip using the ``skip()`` option. Then, pass
68+
your ``FindOptions`` struct as a parameter to the ``find()`` method.
7769

7870
This example runs a ``find()`` operation that performs the following actions:
7971

@@ -97,39 +89,6 @@ This example runs a ``find()`` operation that performs the following actions:
9789
Book { name: "A Dance with Dragons", author: "Martin", length: 1104 }
9890
Book { name: "Atlas Shrugged", author: "Rand", length: 1088 }
9991

100-
.. _rust-findoptions-skip:
101-
102-
Options Example
103-
~~~~~~~~~~~~~~~
104-
105-
Alternatively, if you are setting and reusing options for your query, you can
106-
use ``FindOptions``. Set the ``skip`` field of the ``FindOptions`` struct by
107-
using the ``skip()`` option builder method. Then, chain the ``with_options()``
108-
method to the ``find()`` method and pass your ``FindOptions`` struct as a
109-
parameter to the ``with_options()`` method.
110-
111-
This example runs a ``find()`` operation that performs the following actions:
112-
113-
- Sorts the results in descending order of their ``name`` field values
114-
- Skips the first document
115-
- Returns the remaining documents
116-
117-
.. io-code-block::
118-
:copyable: true
119-
120-
.. input:: /includes/fundamentals/code-snippets/crud/skip.rs
121-
:start-after: start-options-skip-example
122-
:end-before: end-options-skip-example
123-
:language: rust
124-
:dedent:
125-
126-
.. output::
127-
:language: console
128-
:visible: false
129-
130-
Book { name: "Les Misérables", author: "Hugo", length: 1462 }
131-
Book { name: "Atlas Shrugged", author: "Rand", length: 1088 }
132-
13392
.. _rust-aggregation-skip:
13493

13594
Aggregation Example
@@ -171,6 +130,7 @@ To learn more about the operations mentioned in this guide, see the following gu
171130
- :ref:`rust-compound-operations`
172131
- :ref:`rust-aggregation`
173132
- :ref:`rust-sort-guide`
133+
174134
.. - :ref:`rust-limit-guide`
175135

176136
API Documentation

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::env;
2-
use mongodb::{ bson::doc, bson::Document, Client, Collection, options::FindOptions };
2+
use mongodb::{ bson::doc, Client, Collection, options::FindOptions };
33
use serde::{Deserialize, Serialize};
44
use futures::stream::TryStreamExt;
55

@@ -46,36 +46,22 @@ async fn main() -> mongodb::error::Result<()> {
4646
},
4747
];
4848

49-
my_coll.insert_many(books).await?;
49+
my_coll.insert_many(books, None).await?;
5050
// end-sample-data
5151

5252
// Retrieves documents in the collection, sorts results by their "author" field
5353
// values, and skips the first two results.
5454
// start-skip-example
55-
let mut cursor = my_coll
56-
.find(doc! {})
57-
.sort(doc! { "author": 1 })
58-
.skip(2).await?;
59-
60-
while let Some(result) = cursor.try_next().await? {
61-
println!("{:?}", result);
62-
}
63-
// end-skip-example
64-
65-
// Sets the values for the `FindOptions` struct to sort results by their "name"
66-
// field values, skip the first two results, and return the remaining results.
67-
// start-options-skip-example
6855
let find_options = FindOptions::builder()
69-
.sort(doc! { "name": -1 })
70-
.skip(1)
56+
.sort(doc! { "author": 1 })
57+
.skip(2)
7158
.build();
72-
73-
let mut cursor = my_coll.find(doc! {}).with_options(find_options).await?;
59+
let mut cursor = my_coll.find(doc! {}, find_options).await?;
7460

7561
while let Some(result) = cursor.try_next().await? {
7662
println!("{:?}", result);
7763
}
78-
// end-options-skip-example
64+
// end-skip-example
7965

8066
// Retrieves documents in the collection, sorts results by their "author" field,
8167
// then skips the first two results in an aggregation pipeline.
@@ -86,7 +72,7 @@ let pipeline = vec![
8672
doc! { "$skip": 1 },
8773
];
8874

89-
let mut cursor = my_coll.aggregate(pipeline).await?;
75+
let mut cursor = my_coll.aggregate(pipeline, None).await?;
9076

9177
while let Some(result) = cursor.try_next().await? {
9278
println!("{:?}", result);

0 commit comments

Comments
 (0)