Skip to content

Commit c77f3a7

Browse files
sarah-olson-mongodbSarah OlsonSarah Olson
authored
DOCS-14522: Updates to the listIndexes page (#771) (#873)
* DOCS-14522: Update listIndexes based on jira request. * DOCS-14522: Fixing my markup errors. * DOCS-14522: Very minor additional edits * DOCS-14522: Incorporating edits * DOCS-14522: Typo * DOCS-14522: Update codeblock formatting * DOCS-14522: External review feedback * DOCS-14522: Change output section to table. * DOCS-14522: Update Output section * DOCS-14522: Minor format edits * DOCS-14522: Minor format edit * DOCS-14522: Edit to table. * DOCS-14522: Incorporate edits, add examples section. * Review edits : * DOCS-14522: minor edits * DOCS-14522: Incorporate additional feedback. * DOCS-14522: Understanding markup options * DOCS-14522: Minor feedback edits * DOCS-14522: Remove some line breaks * DOCS-14522: Minor edits and format improvements * DOCS-14522: Fix spacing issue in table * DOCS-14522: Fix table spacing markup * DOCS-14522: Fix io-code-block spacing * DOCS-14522: Troubleshooting some issue * DOCS-14522: Troubleshooting some issue * DOCS-14522: Troubleshooting some issue * DOCS-14522: Troubleshooting some issue * DOCS:14522: Troubleshooting some issue * DOCS-14522: Troubleshooting some issue * DOCS-14522: Troubleshooting some issue * DOCS-14522: Add review feedback * DOCS-14522: Testing table markup * DOCS-14522: Review feedback * DOCS-14522: Fix example format Co-authored-by: Sarah Olson <[email protected]> Co-authored-by: Sarah Olson <[email protected]> Co-authored-by: Sarah Olson <[email protected]> Co-authored-by: Sarah Olson <[email protected]>
1 parent 19e9e1d commit c77f3a7

File tree

3 files changed

+180
-55
lines changed

3 files changed

+180
-55
lines changed

source/includes/extracts-4.2-changes.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,9 @@ content: |
515515
ref: 4.2-changes-disconnect
516516
content: |
517517
518-
Starting in MongoDB 4.2, if the client that issued the |operation|
519-
disconnects before the operation completes, MongoDB marks
520-
the |operation| for termination (i.e. :dbcommand:`killOp` on the
521-
operation).
518+
Starting in MongoDB 4.2, if the client that issued |operation|
519+
disconnects before the operation completes, MongoDB marks |operation|
520+
for termination using :dbcommand:`killOp`.
522521
---
523522
ref: 4.2-changes-map-reduce-deprecation
524523
content: |

source/includes/extracts-4.4-changes.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,9 @@ content: |
493493
is in another state, such as :replstate:`STARTUP2`, the
494494
operation errors.
495495
496-
In previous versions, the operations can also be run when the member
497-
is in :replstate:`STARTUP2`. However, the operations wait
498-
until the member transitions to :replstate:`RECOVERING`.
496+
In previous versions, the operations also run when the member
497+
is in :replstate:`STARTUP2`. The operations wait until the member
498+
transitioned to :replstate:`RECOVERING`.
499499
500500
---
501501
ref: 4.4-changes-mapreduce-ignore-verbose

source/reference/command/listIndexes.txt

Lines changed: 174 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,59 @@ Definition
1515

1616
.. dbcommand:: listIndexes
1717

18-
Returns information about the indexes on the specified collection,
19-
including :doc:`hidden indexes </core/index-hidden>`. Specifically,
20-
the command returns a document that contains information with which
21-
to create a cursor to the index information. Index information
22-
includes the keys and options used to create the index.
23-
:binary:`~bin.mongosh` provides the
24-
:method:`db.collection.getIndexes()` helper.
18+
Returns information about the indexes on the specified collection. Returned
19+
index information includes the keys and options used to create the index, as
20+
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.
2523

26-
The command has the following form:
24+
Syntax
25+
------
2726

28-
.. code-block:: javascript
27+
The command has the following form:
2928

30-
{ "listIndexes": "<collection-name>" }
29+
.. code-block:: javascript
30+
31+
db.runCommand (
32+
{
33+
listIndexes: "<collection-name>",
34+
cursor: { batchSize: <int> },
35+
comment: <any>
36+
}
37+
)
3138

39+
Command Fields
40+
~~~~~~~~~~~~~~
3241

33-
.. list-table::
34-
:header-rows: 1
35-
:widths: 20 20 80
36-
37-
* - Field
38-
39-
- Type
40-
41-
- Description
42-
43-
* - ``listIndexes``
42+
``listIndexes`` takes the following fields:
43+
44+
.. list-table::
45+
:header-rows: 1
46+
:widths: 20 20 80
4447

45-
- string
48+
* - Field
49+
- Type
50+
- Description
4651

47-
- The name of the collection.
48-
49-
* - ``comment``
50-
51-
- any
52-
53-
- .. include:: /includes/extracts/comment-content.rst
54-
55-
.. versionadded:: 4.4
56-
57-
52+
* - ``listIndexes``
53+
- string
54+
- The name of the collection.
55+
56+
* - ``cursor.batchSize``
57+
- integer
58+
- Optional. Specifies the cursor batch size.
59+
60+
* - ``comment``
61+
- any
62+
- .. include:: /includes/extracts/comment-content.rst
63+
.. versionadded:: 4.4
5864

5965
Required Access
6066
---------------
6167

62-
To run :dbcommand:`listIndexes` when access control is enforced, users
63-
must have privileges to :authaction:`listIndexes`. The built-in role
64-
:authrole:`read` provides the required privileges to run
65-
:dbcommand:`listIndexes` for the collections in a database.
68+
If access control is enforced, the built-in :authrole:`read` role provides the
69+
required privileges to run :dbcommand:`listIndexes` for the collections in a
70+
database.
6671

6772
Behavior
6873
--------
@@ -86,17 +91,138 @@ Output
8691

8792
.. data:: listIndexes.cursor
8893

89-
A document that contains information with which to create a cursor
90-
to index information. The cursor information includes the cursor id,
91-
the full namespace for the command, as well as the first batch of
92-
results. Index information includes the keys and options used to
93-
create the index. The index option ``hidden``, available starting in
94-
MongoDB 4.4, is only present if the value is ``true``.
95-
96-
For information on the keys and index options, see
97-
:method:`db.collection.createIndex()`.
94+
A result set returned in the batch size specified by your cursor.
95+
Each document in the batch output contains the following fields:
96+
97+
.. list-table::
98+
:header-rows: 1
99+
:widths: 15 15 30
100+
101+
* - Field
102+
- Type
103+
- Description
104+
105+
* - id
106+
- integer
107+
- A 64-bit integer. If zero, there are no more batches of information.
108+
If non-zero, a cursor ID, usable in a ``getMore`` command to get the
109+
next batch of index information.
110+
111+
* - ns
112+
- string
113+
- The database and collection name in the following format:
114+
``<database-name>.<collection-name>``
115+
116+
* - firstBatch
117+
- document
118+
- Index information includes the keys and options used to create the
119+
index. The index option hidden, available starting in MongoDB 4.4,
120+
is only present if the value is true.
121+
122+
Use :dbcommand:`getMore` to retrieve additional results as needed.
123+
98124

99125
.. data:: listIndexes.ok
100126

101-
The return value for the command. A value of ``1`` indicates
102-
success.
127+
The return value for the command. A value of ``1`` indicates success.
128+
129+
Examples
130+
--------
131+
132+
List Database Indexes
133+
~~~~~~~~~~~~~~~~~~~~~
134+
135+
This example lists indexes for the ``contacts`` collection without specifying the
136+
cursor batch size.
137+
138+
.. io-code-block::
139+
:copyable: true
140+
141+
.. input::
142+
:language: json
143+
:linenos:
144+
145+
db.runCommand (
146+
{
147+
listIndexes: "contacts"
148+
}
149+
)
150+
151+
.. output::
152+
:linenos:
153+
154+
{
155+
cursor: {
156+
id: Long("0"),
157+
ns: 'test.contacts',
158+
firstBatch: [
159+
{ v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' },
160+
{ v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' }
161+
]
162+
},
163+
ok: 1
164+
}
165+
166+
Specify Result Batch Size
167+
~~~~~~~~~~~~~~~~~~~~~~~~~
168+
169+
This example lists indexes for the ``contacts`` collection, and specifies a cursor
170+
batch size of 1.
171+
172+
.. io-code-block::
173+
:copyable: true
174+
175+
.. input::
176+
:language: json
177+
:linenos:
178+
179+
db.runCommand (
180+
{
181+
listIndexes: "contacts", cursor: { batchSize: 1 }
182+
}
183+
)
184+
185+
.. output::
186+
:linenos:
187+
188+
{
189+
cursor: {
190+
id: Long("4809221676960028307"),
191+
ns: 'test.contacts',
192+
firstBatch: [ { v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' } ]
193+
},
194+
ok: 1
195+
}
196+
197+
Retrieve Additional Results
198+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
199+
200+
This example uses ``getMore`` to retrieve additional result batches from the
201+
``contacts`` collection.
202+
203+
.. io-code-block::
204+
:copyable: true
205+
206+
.. input::
207+
:language: json
208+
:linenos:
209+
210+
db.runCommand(
211+
{
212+
getMore: Long("4809221676960028307"), collection: "contacts"
213+
}
214+
)
215+
216+
.. output::
217+
:linenos:
218+
219+
{
220+
cursor: {
221+
nextBatch: [ { v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' } ],
222+
id: Long("0"),
223+
ns: 'test.contacts'
224+
},
225+
ok: 1
226+
}
227+
228+

0 commit comments

Comments
 (0)