Skip to content

Commit 8502642

Browse files
authored
DOCSP-24399 cherry-pick/merge (#1782)
1 parent a4ee267 commit 8502642

24 files changed

+103
-67
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
.. tip::
3+
4+
In :program:`mongosh`, this command can also be run through the |method|.
5+
6+
Helper methods are convenient for :program:`mongosh` users, but they may not
7+
return the same level of information as database commands. In cases where
8+
the convenience is not needed or the additional return fields are required,
9+
use the database command.
10+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. important:: ``mongosh`` Method
2+
3+
This page documents a :binary:`~bin.mongosh` method. This is *not*
4+
the documentation for database commands or language-specific drivers,
5+
such as Node.js. To use the database command, see the |dbcommand|.
6+
7+
For MongoDB API drivers, refer to the language-specific
8+
:driver:`MongoDB driver documentation </>`.
9+
10+
For the legacy ``mongo`` shell documentation, refer to the
11+
documentation for the corresponding MongoDB Server release:
12+
13+
- :v4.4:`mongo shell v4.4 </mongo>`
14+
- :v4.2:`mongo shell v4.2 </mongo>`

source/reference/command/aggregate.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Definition
2020
to process data from a collection or other source with a sequence of
2121
stage-based manipulations.
2222

23+
.. |method| replace:: :method:`db.aggregate()` and
24+
:method:`db.collection.aggregate()` helper methods
25+
.. include:: /includes/fact-dbcommand-tip
26+
2327
Syntax
2428
------
2529

source/reference/command/createIndexes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Definition
1717

1818
Builds one or more indexes on a collection.
1919

20+
.. |method| replace:: :method:`db.collection.createIndex()` and
21+
:method:`db.collection.createIndexes()` helper methods.
22+
.. include:: /includes/fact-dbcommand-tip
23+
2024
The :dbcommand:`createIndexes` command takes the following form:
2125

2226
.. code-block:: javascript

source/reference/command/distinct.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Definition
2020
an array of the distinct values. The return document also contains
2121
an embedded document with query statistics and the query plan.
2222

23+
.. |method| replace:: :method:`db.collection.distinct()` helper method.
24+
.. include:: /includes/fact-dbcommand-tip
25+
2326
The command takes the following form
2427

2528
.. code-block:: javascript

source/reference/command/dropIndexes.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ dropIndexes
1616
(except the index on the ``_id`` field) from the specified
1717
collection.
1818

19+
.. |method| replace:: :method:`db.collection.dropIndex()` and
20+
:method:`db.collection.dropIndexes()` helper methods.
21+
.. include:: /includes/fact-dbcommand-tip
22+
1923
The command has the following form:
20-
24+
2125
.. code-block:: javascript
2226

2327
{ dropIndexes: <string>, index: <string|document|arrayofstrings>, writeConcern: <document>, comment: <any> }

source/reference/command/explain.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ Definition
2121
:dbcommand:`findAndModify`, :dbcommand:`delete`,
2222
:dbcommand:`mapReduce`, and :dbcommand:`update`.
2323

24-
Although MongoDB provides the :dbcommand:`explain` command, the
25-
preferred method for running :dbcommand:`explain` is to use the
26-
:method:`db.collection.explain()` and :method:`cursor.explain()` helpers.
24+
.. |method| replace:: :method:`db.collection.explain()` and
25+
:method:`cursor.explain()` helper methods
26+
27+
.. include:: /includes/fact-dbcommand-tip
2728

2829
The :dbcommand:`explain` command has the following syntax:
2930

source/reference/command/find.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ Definition
2020
Executes a query and returns the first batch of results and the
2121
cursor id, from which the client can construct a cursor.
2222

23-
.. tip::
24-
25-
Rather than run the :dbcommand:`find` command directly, you can
26-
use the :method:`db.collection.find()` helper provided in
27-
:binary:`~bin.mongosh` or the equivalent helper in the
28-
drivers.
23+
.. |method| replace:: :method:`db.collection.find()` or
24+
:method:`db.collection.findOne()` helper methods
25+
.. include:: /includes/fact-dbcommand-tip
2926

3027
Syntax
3128
------

source/reference/command/findAndModify.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Definition
2424
modifications made on the update. To return the document with the
2525
modifications made on the update, use the ``new`` option.
2626

27+
.. |method| replace:: :method:`db.collection.findAndModify()` helper method
28+
.. include:: /includes/fact-dbcommand-tip
29+
2730
.. versionchanged:: 5.0
2831

2932
The command has the following syntax:

source/reference/command/insert.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Definition
1919
returns a document containing the status of all inserts. The insert
2020
methods provided by the MongoDB drivers use this command internally.
2121

22+
.. |method| replace:: :method:`db.collection.insertOne()` and
23+
:method:`db.collection.insertMany()` helper methods
24+
.. include:: /includes/fact-dbcommand-tip
25+
2226
The command has the following syntax:
2327

2428
.. code-block:: javascript

source/reference/command/listIndexes.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Definition
1818
Returns information about the indexes on the specified collection. Returned
1919
index information includes the keys and options used to create the index, as
2020
well as :doc:`hidden indexes </core/index-hidden>`. You can optionally set
21-
the batch size for the first batch of results. :binary:`~bin.mongosh`
22-
provides the :method:`db.collection.getIndexes()` helper.
21+
the batch size for the first batch of results.
2322

23+
.. |method| replace:: :method:`db.collection.getIndexes()` helper method
24+
.. include:: /includes/fact-dbcommand-tip
25+
2426
Syntax
2527
------
2628

source/reference/method/db.collection.aggregate.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ Definition
1616
.. method:: db.collection.aggregate(pipeline, options)
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
19+
.. |dbcommand| replace:: :dbcommand:`aggregate` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2021

2122

2223
Calculates aggregate values for the data in a collection or a :doc:`view </core/views>`.
2324

24-
2525
.. list-table::
2626
:header-rows: 1
2727
:widths: 20 20 80

source/reference/method/db.collection.createIndex.txt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ Definition
1717

1818
.. method:: db.collection.createIndex(keys, options, commitQuorum)
1919

20-
21-
.. include:: /includes/fact-mongosh-shell-method.rst
22-
20+
.. |dbcommand| replace:: :dbcommand:`createIndexes` command
21+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2322

2423
Creates indexes on collections.
2524

25+
To minimize the impact of building an index on replica sets and
26+
sharded clusters, use a rolling index build procedure as described
27+
on :doc:`/tutorial/build-indexes-on-replica-sets`.
28+
2629
:method:`db.collection.createIndex()` takes the following parameters:
2730

2831
.. list-table::
@@ -141,14 +144,6 @@ Definition
141144

142145
.. versionadded:: 4.4
143146

144-
145-
The :method:`db.collection.createIndex()` is a wrapper around the
146-
:dbcommand:`createIndexes` command.
147-
148-
To minimize the impact of building an index on replica sets and
149-
sharded clusters, use a rolling index build procedure as described
150-
on :doc:`/tutorial/build-indexes-on-replica-sets`.
151-
152147
.. _ensureIndex-options:
153148
.. _createIndex-options:
154149

source/reference/method/db.collection.createIndexes.txt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ Definition
1515

1616
.. method:: db.collection.createIndexes( [ keyPatterns ], options, commitQuorum )
1717

18-
19-
.. include:: /includes/fact-mongosh-shell-method.rst
20-
18+
.. |dbcommand| replace:: :dbcommand:`createIndexes` command
19+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2120

2221
Creates one or more indexes on a collection.
2322

23+
To minimize the impact of building an index on replica sets and sharded
24+
clusters, use a rolling index build procedure
25+
as described on :doc:`/tutorial/build-indexes-on-replica-sets`.
26+
2427
:method:`db.collection.createIndexes()` takes the following
2528
parameters:
2629

@@ -144,14 +147,6 @@ Definition
144147

145148
.. versionadded:: 4.4
146149

147-
148-
The :method:`db.collection.createIndexes()` is a wrapper around the
149-
:dbcommand:`createIndexes` command.
150-
151-
To minimize the impact of building an index on replica sets and sharded
152-
clusters, use a rolling index build procedure
153-
as described on :doc:`/tutorial/build-indexes-on-replica-sets`.
154-
155150
.. _createIndexes-method-options:
156151

157152
Options

source/reference/method/db.collection.distinct.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ Definition
1616
.. method:: db.collection.distinct(field, query, options)
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
19+
.. |dbcommand| replace:: :dbcommand:`distinct` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2021

2122

2223
Finds the distinct
2324
values for a specified field across a single collection or view and returns
2425
the results in an array.
2526

27+
This method takes the following parameters:
2628

2729
.. list-table::
2830
:header-rows: 1
@@ -57,11 +59,6 @@ Definition
5759
- Optional. A document that specifies the options. See :ref:`distinct-method-options`.
5860

5961

60-
61-
62-
63-
The :method:`db.collection.distinct()` method provides a wrapper
64-
around the :dbcommand:`distinct` command.
6562

6663
.. include:: /includes/note-distinct-bson-limit-agg-alternative.rst
6764

source/reference/method/db.collection.dropIndex.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ Definition
1616
.. method:: db.collection.dropIndex(index)
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
19+
.. |dbcommand| replace:: :dbcommand:`dropIndexes` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2021

2122

22-
Drops or removes the specified index from a collection. The
23-
:method:`db.collection.dropIndex()` method provides a wrapper around
24-
the :dbcommand:`dropIndexes` command.
25-
23+
Drops or removes the specified index from a collection.
24+
2625
.. note::
2726

2827
- You cannot drop the default index on the ``_id`` field.
@@ -32,6 +31,10 @@ Definition
3231
<db.collection.dropIndex>` to drop all non-``_id`` indexes. Use
3332
:method:`db.collection.dropIndexes()` instead.
3433

34+
To get the index name or the index specification document for the
35+
:method:`db.collection.dropIndex()` method, use the
36+
:method:`db.collection.getIndexes()` method.
37+
3538
The :method:`db.collection.dropIndex()` method takes the following
3639
parameter:
3740

@@ -72,9 +75,6 @@ Definition
7275
:ref:`dropIndex-method-index-builds` for more complete
7376
documentation.
7477

75-
To get the index name or the index specification document for the
76-
:method:`db.collection.dropIndex()` method, use the
77-
:method:`db.collection.getIndexes()` method.
7878

7979
Behavior
8080
--------

source/reference/method/db.collection.dropIndexes.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Definition
1717
.. method:: db.collection.dropIndexes()
1818

1919

20-
.. include:: /includes/fact-mongosh-shell-method.rst
20+
.. |dbcommand| replace:: :dbcommand:`dropIndexes` command
21+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2122

2223

2324
Drops the specified index or indexes (except the index on the
@@ -102,9 +103,6 @@ Definition
102103
**To drop multiple indexes** (Available starting in MongoDB
103104
4.2), specify an array of the index names.
104105

105-
106-
The :method:`db.collection.dropIndexes()` is a wrapper around the
107-
:dbcommand:`dropIndexes` command.
108106

109107
Behavior
110108
--------

source/reference/method/db.collection.explain.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Description
1616
.. method:: db.collection.explain()
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
19+
.. |dbcommand| replace:: :dbcommand:`explain` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2021

2122

2223
Returns information on the query plan for the following methods:

source/reference/method/db.collection.find.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ Definition
1616
.. method:: db.collection.find(query, projection, options)
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
20-
19+
.. |dbcommand| replace:: :dbcommand:`find` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2121

2222
Selects documents in a collection or view and returns a
2323
:term:`cursor` to the selected documents.
2424

25-
2625
.. list-table::
2726
:header-rows: 1
2827
:widths: 20 20 80

source/reference/method/db.collection.findAndModify.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ Definition
1919

2020
.. method:: db.collection.findAndModify(document)
2121

22-
.. include:: /includes/fact-mongosh-shell-method.rst
22+
.. |dbcommand| replace:: :dbcommand:`findAndModify` command
23+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2324

2425
Modifies and returns a single document. By default, the returned
2526
document does not include the modifications made on the update. To
2627
return the document with the modifications made on the update, use
27-
the ``new`` option. The :method:`~db.collection.findAndModify()`
28-
method is a shell helper around the :dbcommand:`findAndModify`
29-
command.
28+
the ``new`` option.
3029

3130
.. versionchanged:: 5.0
3231

source/reference/method/db.collection.findOne.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Definition
1616
.. method:: db.collection.findOne(query, projection, options)
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
19+
.. |dbcommand| replace:: :dbcommand:`find` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2021

2122

2223
Returns one document that satisfies the specified query criteria on

source/reference/method/db.collection.getIndexes.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ Definition
1616
.. method:: db.collection.getIndexes()
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
19+
.. |dbcommand| replace:: :dbcommand:`listIndexes` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2021

2122

2223
Returns an array that holds a list of documents that identify and
2324
describe the existing indexes on the collection, including
24-
:doc:`hidden indexes </core/index-hidden>`. You must call
25+
:doc:`hidden indexes </core/index-hidden>`.
26+
27+
You must call
2528
:method:`db.collection.getIndexes()` on a collection. For example:
2629

2730
.. code-block:: javascript

source/reference/method/db.collection.insertMany.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Definition
1616
.. method:: db.collection.insertMany()
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
19+
.. |dbcommand| replace:: :dbcommand:`insert` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2021

2122
Inserts multiple documents into a collection.
2223

source/reference/method/db.collection.insertOne.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Definition
1616
.. method:: db.collection.insertOne()
1717

1818

19-
.. include:: /includes/fact-mongosh-shell-method.rst
19+
.. |dbcommand| replace:: :dbcommand:`insert` command
20+
.. include:: /includes/fact-mongosh-shell-method-alt.rst
2021

2122
Inserts a single document into a collection.
2223

0 commit comments

Comments
 (0)