@@ -986,6 +986,69 @@ the default scope being evaluated first:
986
986
embedded: false>
987
987
988
988
989
+ Pagination
990
+ ==========
991
+
992
+ Mongoid provides the pagination operators ``limit``, ``skip``, and ``batch_size`` on ``Criteria``.
993
+
994
+ .. _limit:
995
+
996
+ ``limit``
997
+ ---------
998
+
999
+ ``limit`` sets the total number of documents to be returned by a query:
1000
+
1001
+ .. code-block:: ruby
1002
+
1003
+ Band.limit(5)
1004
+ # =>
1005
+ # #<Mongoid::Criteria
1006
+ # selector: {}
1007
+ # options: {:limit=>5}
1008
+ # class: Band
1009
+ # embedded: false>
1010
+
1011
+ .. _skip:
1012
+
1013
+ ``skip``
1014
+ --------
1015
+
1016
+ ``skip`` (alias: ``offset``) sets the number of query results to skip
1017
+ before returning documents. The ``limit`` value, if specified, will be applied
1018
+ after documents are skipped. When performing pagination, ``skip`` is recommended
1019
+ to be combined with :ref:`ordering <ordering>` to ensure consistent results.
1020
+
1021
+ .. code-block:: ruby
1022
+
1023
+ Band.skip(10)
1024
+ # =>
1025
+ # #<Mongoid::Criteria
1026
+ # selector: {}
1027
+ # options: {:skip=>10}
1028
+ # class: Band
1029
+ # embedded: false>
1030
+
1031
+ .. _batch-size:
1032
+
1033
+ ``batch_size``
1034
+ --------
1035
+
1036
+ When executing large queries, or when iterating over query results with an enumerator method such as
1037
+ ``Criteria#each``, Mongoid automatically uses the `MongoDB getMore command
1038
+ <https://docs.mongodb.com/manual/reference/command/getMore/>`_ to load results in batches.
1039
+ The default ``batch_size`` is 1000, however you may set it explicitly:
1040
+
1041
+ .. code-block:: ruby
1042
+
1043
+ Band.batch_size(500)
1044
+ # =>
1045
+ # #<Mongoid::Criteria
1046
+ # selector: {}
1047
+ # options: {:batch_size=>500}
1048
+ # class: Band
1049
+ # embedded: false>
1050
+
1051
+
989
1052
.. _query-cache:
990
1053
991
1054
Query Cache
@@ -1580,6 +1643,11 @@ Mongoid supports persistence operations off of criteria
1580
1643
in a light capacity for when you want to expressively perform multi
1581
1644
document inserts, updates, and deletion.
1582
1645
1646
+ .. warning::
1647
+
1648
+ Criteria ordering and pagination conditions, including ``order``, ``limit``,
1649
+ ``offset``, and ``batch_size``, will be ignored on the following operations.
1650
+
1583
1651
.. list-table::
1584
1652
:header-rows: 1
1585
1653
:widths: 30 60
0 commit comments