/
listCollections.txt
160 lines (105 loc) · 3.8 KB
/
listCollections.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
===============
listCollections
===============
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. versionadded:: 3.0.0
Definition
----------
.. dbcommand:: listCollections
Retrieve information, i.e. the name and options, about the
collections and :doc:`views </core/views>` in a database. Specifically, the command returns a
document that contains information with which to create a
cursor to the collection information. The :binary:`~bin.mongo` shell
provides the :method:`db.getCollectionInfos()` and the
:method:`db.getCollectionNames()` helper methods.
The command has the following form:
.. code-block:: javascript
{ listCollections: 1, filter: <document> }
The :dbcommand:`listCollections` command can take the following
optional field:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Field
- Type
- Description
* - ``filter``
- document
- Optional. A query expression to filter the list of collections.
You can specify a query expression on any of the :ref:`fields
returned <list-collection-output>` in the result set.
.. _listCollections-behavior:
Behavior
--------
Use a filter to limit the results of :dbcommand:`listCollections`. You
can specify a filter on any of the :ref:`fields returned
<list-collection-output>` in the :dbcommand:`listCollections` result
set.
.. _list-collection-output:
Output
------
.. data:: listCollections.cursor
A document that contains information with which to create a cursor
to documents that contain collection names and options. The cursor
information includes the cursor id, the full namespace for the
command, as well as the first batch of results. Each document in the
batch output contains the following fields:
.. list-table::
:header-rows: 1
:widths: 10 10 30
* - Field
- Type
- Description
* - name
- String
- Name of the collection.
* - type
- String
- Type of data store:
- ``collection`` for :manual:`collections
</core/databases-and-collections/#collections>`.
- ``view`` for :manual:`views </core/views/>`.
* - options
- Document
- Collection options.
These options correspond directly to the options available in
:method:`db.createCollection()`, with the exception of the
``"options.flags"``. The ``"options.flags"`` corresponds to
the ``usePowerOf2Sizes`` and the ``noPadding`` options in the
:method:`db.createCollection()` method:
.. include:: /includes/list-collection-user-flags.rst
For the descriptions on the options, see
:method:`db.createCollection()`.
* - info
- Document
- Lists the following fields related to the collection:
readOnly
``boolean``. If ``true``, the data store is read only.
* - idIndex
- Document
- Provides information on the ``_id`` index for the
collection.
.. data:: listCollections.ok
The return value for the command. A value of ``1`` indicates
success.
.. data:: listCollections.ok
The return value for the command. A value of ``1`` indicates
success.
Required Access
---------------
.. include:: /includes/extracts/actions-listCollections.rst
Example
-------
List All Collections
~~~~~~~~~~~~~~~~~~~~
The following example uses the :method:`db.getCollectionInfos()` helper
to return information for all collections in the ``records`` database:
.. code-block:: javascript
use records
db.getCollectionInfos();
.. seealso:: :method:`db.getCollectionInfos()`