@@ -60,53 +60,15 @@ Limit Documents
6060You can specify the maximum number of documents to return in a query or in an
6161aggregation pipeline.
6262
63- This section describes how to limit results in the following ways:
64-
65- - :ref:`limit() method <rust-limit-method>`: Chain the ``limit()`` method to the
66- ``find()`` method
67- - :ref:`FindOptions struct <rust-findoptions-limit>`: Use the ``limit`` option
68- - :ref:`Aggregation pipleline <rust-aggregation-limit>`: Create a pipeline that uses the ``$limit`` stage
69-
7063.. _rust-limit-method:
7164
72- limit() Method Example
73- ~~~~~~~~~~~~~~~~~~~~~~~
65+ Query Results Example
66+ ~~~~~~~~~~~~~~~~~~~~~
7467
75- To limit the number of documents returned, you can chain the ``limit()`` method
76- to the ``find()`` method.
77-
78- This example runs a ``find()`` operation that performs the following actions:
79-
80- - Sorts the results in ascending order of their ``length`` field values
81- - Limits the results to the first three documents
82-
83- .. io-code-block::
84- :copyable: true
85-
86- .. input:: /includes/fundamentals/code-snippets/crud/limit.rs
87- :start-after: start-limit-example
88- :end-before: end-limit-example
89- :language: rust
90- :dedent:
91-
92- .. output::
93- :language: console
94- :visible: false
95-
96- Book { name: "The Brothers Karamazov", author: "Dostoyevsky", length: 824 }
97- Book { name: "Atlas Shrugged", author: "Rand", length: 1088 }
98- Book { name: "A Dance with Dragons", author: "Martin", length: 1104 }
99-
100- .. _rust-findoptions-limit:
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 ``limit`` field of the ``FindOptions`` struct by
107- using the ``limit()`` 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.
68+ To limit the number of documents returned, you can initialize a ``FindOptions``
69+ instance and specify the number of documents you want to limit using the
70+ ``limit()`` method. Then, pass your ``FindOptions`` struct as a parameter to the
71+ ``find()`` method.
11072
11173This example runs a ``find()`` operation that performs the following actions:
11274
@@ -119,8 +81,8 @@ This example runs a ``find()`` operation that performs the following actions:
11981 :copyable: true
12082
12183 .. input:: /includes/fundamentals/code-snippets/crud/limit.rs
122- :start-after: start-limit-options- example
123- :end-before: end-limit-options- example
84+ :start-after: start-limit-example
85+ :end-before: end-limit-example
12486 :language: rust
12587 :dedent:
12688
@@ -158,8 +120,8 @@ This example runs an aggregation pipeline that performs the following actions:
158120 :language: console
159121 :visible: false
160122
161- Document({"_id": Int32(3 ), "name": String("Les Misérables"), "author": String("Hugo"), "length": Int32(1462)})
162- Document({"_id": Int32(4 ), "name": String("A Dance with Dragons"), "author": String("Martin"), "length": Int32(1104)})
123+ Document({"_id": ObjectId("..." ), "name": String("Les Misérables"), "author": String("Hugo"), "length": Int32(1462)})
124+ Document({"_id": ObjectId("..." ), "name": String("A Dance with Dragons"), "author": String("Martin"), "length": Int32(1104)})
163125
164126Additional Information
165127----------------------
0 commit comments