Skip to content

DOCS-6621 : Move $natural to cursor.hint() #2446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/redirects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -960,4 +960,11 @@ type: 'redirect'
code: 303
outputs:
- 'before-v3.0'
---
from : '/reference/operator/query-modifier'
to: '/reference/method/js-cursor'
type: 'redirect'
code: 303
outputs:
- 'after-v3.0'
...
5 changes: 5 additions & 0 deletions source/includes/apiargs-method-cursor.hint-param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ description: |
The index to "hint" or force MongoDB to use when performing the query.
Specify the index either by the index name or by the index
specification document.

You can also specify ``{ $natural : 1 }`` to force the query to perform a
forwards collection scan, or ``{ $natural : -1 }`` for a reverse
collection scan.

interface: method
name: index
operation: cursor.hint
Expand Down
4 changes: 0 additions & 4 deletions source/includes/toc-operator-landing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ file: /reference/operator/aggregation
description: |
Aggregation pipeline operations have a collection of operators
available to define and manipulate documents in pipeline stages.
---
file: /reference/operator/query-modifier
description: |
Query modifiers determine the way that queries will be executed.
...
14 changes: 14 additions & 0 deletions source/reference/method/cursor.hint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ You can also specify the index using the index name:
.. code-block:: javascript

db.users.find().hint( "age_1" )

You can specify ``{ $natural : 1 }`` to force the query to perform a forwards
collection scan:

.. code-block:: javascript

db.users.find().hint( { $natural : 1 } )

You can also specify ``{ $natural : -1 }`` to force the query to perform a
reverse collection scan:

.. code-block:: javascript

db.users.find().hint( { $natural : -1 } )

.. seealso::

Expand Down
2 changes: 2 additions & 0 deletions source/reference/method/js-cursor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Cursor Methods

.. default-domain:: mongodb

These methods modify the way that the underlying query is executed.

.. include:: /includes/toc/table-method-cursor.rst

.. include:: /includes/toc/method-cursor.rst
43 changes: 3 additions & 40 deletions source/reference/operator/meta/natural.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,8 @@ $natural
Definition
----------

.. operator:: $natural

Use the :operator:`$natural` operator to use :term:`natural order` for
the results of a sort operation. Natural order refers to the logical
:ref:`ordering <return-natural-order>` of documents internally within the
database.

The :operator:`$natural` operator uses the following syntax to return
documents in the order they exist on disk:

.. code-block:: javascript

db.collection.find().sort( { $natural: 1 } )

Behavior
--------

On a sharded collection the :operator:`$natural` operator returns a
collection scan sorted in :ref:`natural order <return-natural-order>`, the
order the database inserts and stores documents on disk.

.. include:: /includes/fact-natural-parameter.rst
.. versionchanged:: 3.2

.. include:: /includes/fact-natural-sort-order-text-query-restriction.rst

Examples
--------

Reverse Order
~~~~~~~~~~~~~

Use ``{ $natural: -1 }`` to return documents in the reverse order as
they occur on disk:

.. code-block:: javascript

db.collection.find().sort( { $natural: -1 } )

Additional Information
----------------------
.. operator:: $natural

:method:`cursor.sort()`
See :method:`cursor.hint()` for :operator:`$natural` usage.
19 changes: 1 addition & 18 deletions source/reference/operator/query-modifier.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ Query Modifiers

.. default-domain:: mongodb

Introduction
------------

MongoDB provides :doc:`cursor methods </reference/method/js-cursor>` for
setting options on a query.

Operators
---------

Modifiers
~~~~~~~~~

See :doc:`/reference/method/js-cursor` for query modifiers.

Sort Order
~~~~~~~~~~

.. include:: /includes/toc/table-operator-sort-order.rst
setting options or modifiers on a query.

.. include:: /includes/toc/operator-sort-order.rst