Skip to content

Commit 45f5d95

Browse files
sarah-olson-mongodbSarah OlsonSarah Olson
authored
Docs 14522 v4.2 (#877)
* DOCS-14522: Updates to the listIndexes page (#771) * 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 * DOCS-14522: Resolve 4.2 merge conflicts Co-authored-by: Sarah Olson <[email protected]> Co-authored-by: Sarah Olson <[email protected]> * DOCS-14522: Fixing code box for v4.2 and 4.0 * DOCS-14522: Example cleanup * DOCS-14522: Minor additional edits for code-block * DOCS-14522: Minor codeblock edit : * DOCS-14522: Minor codeblock edit * Empty commit * DOCS-14522: Remove unnecessary file from the 4.2 branch Co-authored-by: Sarah Olson <[email protected]> Co-authored-by: Sarah Olson <[email protected]>
1 parent 632f031 commit 45f5d95

File tree

2 files changed

+168
-41
lines changed

2 files changed

+168
-41
lines changed

source/includes/extracts-4.2-changes.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,9 @@ content: |
498498
ref: 4.2-changes-disconnect
499499
content: |
500500
501-
Starting in MongoDB 4.2, if the client that issued the |operation|
502-
disconnects before the operation completes, MongoDB marks
503-
the |operation| for termination (i.e. :dbcommand:`killOp` on the
504-
operation).
501+
Starting in MongoDB 4.2, if the client that issued |operation|
502+
disconnects before the operation completes, MongoDB marks |operation|
503+
for termination using :dbcommand:`killOp`.
505504
---
506505
ref: 4.2-changes-map-reduce-deprecation
507506
content: |

source/reference/command/listIndexes.txt

Lines changed: 165 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,53 @@ Definition
1515

1616
.. dbcommand:: listIndexes
1717

18-
Returns information about the indexes on the specified collection.
19-
Specifically, the command returns a document that contains
20-
information with which to create a cursor to the index information.
21-
Index information includes the keys and options used to create the
22-
index. The :binary:`~bin.mongo` shell provides the
23-
: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.
20+
You can optionally set the batch size for the first batch of results. The :binary:`~bin.mongo`
21+
shell provides the :method:`db.collection.getIndexes()` helper.
2422

25-
The command has the following form:
23+
Syntax
24+
------
2625

27-
.. code-block:: javascript
26+
The command has the following form:
2827

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

38+
Command Fields
39+
~~~~~~~~~~~~~~
3140

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

46-
- The name of the collection.
47-
48-
47+
* - Field
48+
- Type
49+
- Description
4950

51+
* - ``listIndexes``
52+
- string
53+
- The name of the collection.
5054

55+
* - ``cursor.batchSize``
56+
- integer
57+
- Optional. Specifies the cursor batch size.
5158

5259
Required Access
5360
---------------
5461

55-
To run :dbcommand:`listIndexes` when access control is enforced, users
56-
must have privileges to :authaction:`listIndexes`. The built-in role
57-
:authrole:`read` provides the required privileges to run
58-
:dbcommand:`listIndexes` for the collections in a database.
62+
If access control is enforced, the built-in :authrole:`read` role provides the
63+
required privileges to run :dbcommand:`listIndexes` for the collections in a
64+
database.
5965

6066
Behavior
6167
--------
@@ -72,14 +78,136 @@ Output
7278

7379
.. data:: listIndexes.cursor
7480

75-
A document that contains information with which to create a cursor
76-
to index information. The cursor information includes the cursor id,
77-
the full namespace for the command, as well as the first batch of
78-
results. Index information includes the keys and options used to
79-
create the index. For information on the keys and index options, see
80-
:method:`db.collection.createIndex()`.
81+
A result set returned in the batch size specified by your cursor.
82+
Each document in the batch output contains the following fields:
83+
84+
.. list-table::
85+
:header-rows: 1
86+
:widths: 15 15 30
87+
88+
* - Field
89+
- Type
90+
- Description
91+
92+
* - id
93+
- integer
94+
- A 64-bit integer. If zero, there are no more batches of information.
95+
If non-zero, a cursor ID, usable in a ``getMore`` command to get the
96+
next batch of index information.
97+
98+
* - ns
99+
- string
100+
- The database and collection name in the following format:
101+
``<database-name>.<collection-name>``
102+
103+
* - firstBatch
104+
- document
105+
- Index information includes the keys and options used to create the
106+
index.
107+
108+
Use :dbcommand:`getMore` to retrieve additional results as needed.
109+
81110

82111
.. data:: listIndexes.ok
83112

84-
The return value for the command. A value of ``1`` indicates
85-
success.
113+
The return value for the command. A value of ``1`` indicates success.
114+
115+
Examples
116+
--------
117+
118+
List Database Indexes
119+
~~~~~~~~~~~~~~~~~~~~~
120+
121+
In this example, you list indexes for the ``contacts`` collection without
122+
specifying the cursor batch size.
123+
124+
.. code-block:: javascript
125+
:copyable: true
126+
:linenos:
127+
128+
db.runCommand (
129+
{
130+
listIndexes: "contacts"
131+
}
132+
)
133+
134+
Your results will be similar to:
135+
136+
.. code-block:: javascript
137+
:copyable: false
138+
:linenos:
139+
140+
{
141+
cursor: {
142+
id: Long("0"),
143+
ns: 'test.contacts',
144+
firstBatch: [
145+
{ v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' },
146+
{ v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' }
147+
]
148+
},
149+
ok: 1
150+
}
151+
152+
Specify Result Batch Size
153+
~~~~~~~~~~~~~~~~~~~~~~~~~
154+
155+
In this example, you list indexes for the ``contacts`` collection, and
156+
specify a cursor batch size of 1.
157+
158+
.. code-block:: javascript
159+
:linenos:
160+
:copyable: true
161+
162+
db.runCommand (
163+
{
164+
listIndexes: "contacts", cursor: { batchSize: 1 }
165+
}
166+
)
167+
168+
Your results will be similar to:
169+
170+
.. code-block:: javascript
171+
:copyable: false
172+
:linenos:
173+
174+
{
175+
cursor: {
176+
id: Long("4809221676960028307"),
177+
ns: 'test.contacts',
178+
firstBatch: [ { v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' } ]
179+
},
180+
ok: 1
181+
}
182+
183+
Retrieve Additional Results
184+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
185+
186+
In this example, you use ``getMore`` to retrieve additional result batches from
187+
the ``contacts`` collection.
188+
189+
.. code-block:: javascript
190+
:copyable: true
191+
:linenos:
192+
193+
db.runCommand (
194+
{
195+
getMore: Long("4809221676960028307"), collection: "contacts"
196+
}
197+
)
198+
199+
Your results will be similar to:
200+
201+
.. code-block:: javascript
202+
:copyable: false
203+
:linenos:
204+
205+
{
206+
cursor: {
207+
nextBatch: [ { v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' } ],
208+
id: Long("0"),
209+
ns: 'test.contacts'
210+
},
211+
ok: 1
212+
}
213+

0 commit comments

Comments
 (0)