@@ -40,7 +40,7 @@ in the ``courses`` collection:
40
40
:dedent:
41
41
42
42
To run the examples in this guide, load the sample data into the
43
- ``db.courses`` collection with the following snippet:
43
+ ``db.courses`` collection by using the following snippet:
44
44
45
45
.. literalinclude:: /includes/fundamentals/code-snippets/CRUD/sort.go
46
46
:language: go
@@ -50,7 +50,7 @@ To run the examples in this guide, load the sample data into the
50
50
51
51
.. include:: /includes/fundamentals/automatic-db-coll-creation.rst
52
52
53
- Each document contains a description of a university course that
53
+ Each document represents a description of a university course and
54
54
includes the course title and maximum enrollment, corresponding to
55
55
the ``title`` and ``enrollment`` fields in each document.
56
56
62
62
To specify the order of your results, pass an interface specifying the
63
63
sort fields and direction to the ``SetSort()`` method of an operation's options.
64
64
65
- The following operations take options as a parameter :
65
+ The following operations take ``SetSort()`` as an option :
66
66
67
67
- ``Find()``
68
68
- ``FindOne()``
@@ -229,7 +229,7 @@ Aggregation
229
229
~~~~~~~~~~~
230
230
231
231
You can also include the :manual:`$sort </reference/operator/aggregation/sort/>`
232
- stage to specify a sort in an aggregation pipeline.
232
+ stage to specify a sort in an aggregation pipeline.
233
233
234
234
Example
235
235
```````
@@ -277,7 +277,7 @@ To skip a specified number of returned results from a query, pass the
277
277
number of documents you want to skip to the ``SetSkip()`` method of
278
278
the read operation's options.
279
279
280
- The following read operations take an options object as a parameter :
280
+ The following read operations take ``SetSkip()`` as an option :
281
281
282
282
- ``Find()``
283
283
- ``FindOne()``
@@ -287,11 +287,6 @@ The following read operations take an options object as a parameter:
287
287
If the number of documents exceeds the number of matched documents for a
288
288
query, that query returns no documents.
289
289
290
- .. tip::
291
-
292
- Passing in a negative number to the ``SetSkip()`` method results
293
- in a runtime error.
294
-
295
290
Find operations return documents in a natural order that is not sorted
296
291
on any field. To avoid skipping random documents, use the ``SetSort()``
297
292
method to sort documents on a field with unique values before setting a
@@ -383,7 +378,7 @@ To limit the number of documents returned from a query, pass the
383
378
number of documents you want returned to the ``SetLimit()`` method of
384
379
the read operation's options.
385
380
386
- The following read operations take an options object as a parameter :
381
+ The following read operations take ``SetLimit()`` as an option :
387
382
388
383
- ``Find()``
389
384
- ``CountDocuments()``
@@ -429,7 +424,14 @@ Multiple Options
429
424
~~~~~~~~~~~~~~~~
430
425
431
426
The driver performs the limit behavior last regardless of the order in which you set
432
- any other options.
427
+ any other options. For example, the following option configurations produce the same
428
+ result, regardless of the order in which ``SetLimit()`` is called:
429
+
430
+ .. code-block:: go
431
+ :copyable: false
432
+
433
+ opts := options.Find().SetSort(bson.D{{"enrollment", -1}}).SetSkip(1).SetLimit(2)
434
+ opts := options.Find().SetLimit(2).SetSort(bson.D{{"enrollment", -1}}).SetSkip(1)
433
435
434
436
The following example performs a ``Find()`` operation with the following behavior:
435
437
@@ -464,19 +466,6 @@ The following example performs a ``Find()`` operation with the following behavio
464
466
{"title":"Abstract Algebra","enrollment":60}
465
467
{"title":"Plate Tectonics","enrollment":35}
466
468
467
- .. tip::
468
-
469
- Using any of the following option configurations also produces the same result:
470
-
471
- .. code-block:: go
472
- :copyable: false
473
-
474
- opts := options.Find().SetSort(bson.D{{"enrollment", -1}}).SetSkip(1).SetLimit(2)
475
- opts := options.Find().SetLimit(2).SetSort(bson.D{{"enrollment", -1}}).SetSkip(1)
476
- opts := options.Find().SetLimit(2).SetSkip(1).SetSort(bson.D{{"enrollment", -1}})
477
- opts := options.Find().SetSkip(1).SetSort(bson.D{{"enrollment", -1}}).SetLimit(2)
478
- opts := options.Find().SetSkip(1).SetLimit(2).SetSort(bson.D{{"enrollment", -1}})
479
-
480
469
.. _golang-limit-aggregation:
481
470
482
471
Aggregation
@@ -521,14 +510,12 @@ The following example shows how to return three documents:
521
510
Additional Information
522
511
----------------------
523
512
524
- To learn more about the operations mentioned , see the following
525
- guides :
513
+ To learn more about the operations discussed in this guide , see the following
514
+ documentation :
526
515
527
516
- :ref:`golang-query-document`
528
517
- :ref:`golang-retrieve`
529
518
- :ref:`golang-compound-operations`
530
- - :ref:`golang-sort-results`
531
- - :ref:`golang-skip`
532
519
- :ref:`golang-aggregation`
533
520
534
521
To learn about sorting text scores from your text search, see :ref:`golang-search-text`.
0 commit comments