@@ -17,58 +17,188 @@ Definition
17
17
18
18
.. dbcommand:: listIndexes
19
19
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.
26
24
27
- The command has the following form:
25
+ Syntax
26
+ ------
28
27
29
- .. code-block:: javascript
28
+ The command has the following form:
30
29
31
- { "listIndexes": "<collection-name>" }
30
+ .. code-block:: javascript
31
+
32
+ db.runCommand (
33
+ {
34
+ listIndexes: "<collection-name>",
35
+ cursor: { batchSize: <int> },
36
+ }
37
+ )
32
38
39
+ Command Fields
40
+ ~~~~~~~~~~~~~~
33
41
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
47
47
48
- - The name of the collection.
49
-
50
-
48
+ * - Field
49
+ - Type
50
+ - Description
51
51
52
+ * - ``listIndexes``
53
+ - string
54
+ - The name of the collection.
52
55
56
+ * - ``cursor.batchSize``
57
+ - integer
58
+ - Optional. Specifies the cursor batch size.
53
59
54
60
Required Access
55
61
---------------
56
62
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.
58
66
59
67
Output
60
68
------
61
69
62
70
.. data:: listIndexes.cursor
63
71
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
+
70
101
71
102
.. data:: listIndexes.ok
72
103
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