Skip to content

Commit d7a5e19

Browse files
sarah-olson-mongodbSarah OlsonSarah Olson
authored
Docs 14522 v4.0 (#879)
* 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: Fix merge conflicts Co-authored-by: Sarah Olson <[email protected]> Co-authored-by: Sarah Olson <[email protected]> * DOCS-14522: Fix code block for 4.0 branch * DOCS-14522: Removed unnecessary files from 4.0 branch Co-authored-by: Sarah Olson <[email protected]> Co-authored-by: Sarah Olson <[email protected]>
1 parent 6642aff commit d7a5e19

File tree

1 file changed

+164
-34
lines changed

1 file changed

+164
-34
lines changed

source/reference/command/listIndexes.txt

Lines changed: 164 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,188 @@ Definition
1717

1818
.. dbcommand:: listIndexes
1919

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

27-
The command has the following form:
25+
Syntax
26+
------
2827

29-
.. code-block:: javascript
28+
The command has the following form:
3029

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

39+
Command Fields
40+
~~~~~~~~~~~~~~
3341

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

48-
- The name of the collection.
49-
50-
48+
* - Field
49+
- Type
50+
- Description
5151

52+
* - ``listIndexes``
53+
- string
54+
- The name of the collection.
5255

56+
* - ``cursor.batchSize``
57+
- integer
58+
- Optional. Specifies the cursor batch size.
5359

5460
Required Access
5561
---------------
5662

57-
.. include:: /includes/extracts/actions-listIndexes.rst
63+
If access control is enforced, the built-in :authrole:`read` role provides the
64+
required privileges to run :dbcommand:`listIndexes` for the collections in a
65+
database.
5866

5967
Output
6068
------
6169

6270
.. data:: listIndexes.cursor
6371

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

71102
.. data:: listIndexes.ok
72103

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

0 commit comments

Comments
 (0)