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