@@ -15,47 +15,53 @@ Definition
15
15
16
16
.. dbcommand:: listIndexes
17
17
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.
24
22
25
- The command has the following form:
23
+ Syntax
24
+ ------
26
25
27
- .. code-block:: javascript
26
+ The command has the following form:
28
27
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
+ )
30
37
38
+ Command Fields
39
+ ~~~~~~~~~~~~~~
31
40
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
45
46
46
- - The name of the collection.
47
-
48
-
47
+ * - Field
48
+ - Type
49
+ - Description
49
50
51
+ * - ``listIndexes``
52
+ - string
53
+ - The name of the collection.
50
54
55
+ * - ``cursor.batchSize``
56
+ - integer
57
+ - Optional. Specifies the cursor batch size.
51
58
52
59
Required Access
53
60
---------------
54
61
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.
59
65
60
66
Behavior
61
67
--------
@@ -72,14 +78,136 @@ Output
72
78
73
79
.. data:: listIndexes.cursor
74
80
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
+
81
110
82
111
.. data:: listIndexes.ok
83
112
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