forked from mongodb/docs-php-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMongoDBDatabase-listCollections.txt
166 lines (123 loc) · 3.65 KB
/
MongoDBDatabase-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
161
162
163
164
165
166
====================================
MongoDB\\Database::listCollections()
====================================
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\Database::listCollections()
Returns information for all collections in this database.
.. code-block:: php
function listCollections(array $options = []): Iterator
Parameters
----------
``$options`` : array
An array specifying the desired options.
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Name
- Type
- Description
* - authorizedCollections
- boolean
- A flag that determines which collections are returned based on the user
privileges when access control is enabled. For more information, see
the :manual:`listCollections </reference/command/listCollections>`
command documentation.
For servers < 4.0, this option is ignored.
.. versionadded:: 1.12
* - comment
- mixed
- .. include:: /includes/extracts/common-option-comment.rst
.. include:: /includes/extracts/option-requires-4.4.rst
.. versionadded:: 1.13
* - filter
- array|object
- A query expression to filter the list of collections.
You can specify a query expression for collection fields (e.g.
``name``, ``options``).
* - maxTimeMS
- integer
- .. include:: /includes/extracts/common-option-maxTimeMS.rst
* - session
- :php:`MongoDB\Driver\Session <class.mongodb-driver-session>`
- .. include:: /includes/extracts/common-option-session.rst
.. versionadded:: 1.3
Return Values
-------------
An :php:`Iterator <manual/en/class.iterator.php>`
instance, which provides a :phpclass:`MongoDB\Model\CollectionInfo`
object for each collection in the database.
Example
-------
The following example lists all of the collections in the ``test`` database:
.. code-block:: php
<?php
$database = (new MongoDB\Client)->test;
foreach ($database->listCollections() as $collectionInfo) {
var_dump($collectionInfo);
}
The output would then resemble:
.. code-block:: none
object(MongoDB\Model\CollectionInfo)#3 (2) {
["name"]=>
string(11) "restaurants"
["options"]=>
array(0) {
}
}
object(MongoDB\Model\CollectionInfo)#3 (2) {
["name"]=>
string(5) "users"
["options"]=>
array(0) {
}
}
object(MongoDB\Model\CollectionInfo)#3 (2) {
["name"]=>
string(6) "restos"
["options"]=>
array(0) {
}
}
The following example lists all collections whose name starts with ``"rest"``
in the ``test`` database:
.. code-block:: php
<?php
$database = (new MongoDB\Client)->test;
$collections = $database->listCollections([
'filter' => [
'name' => new MongoDB\BSON\Regex('^rest.*'),
],
]);
foreach ($collections as $collectionInfo) {
var_dump($collectionInfo);
}
The output would then resemble:
.. code-block:: none
object(MongoDB\Model\CollectionInfo)#3 (2) {
["name"]=>
string(11) "restaurants"
["options"]=>
array(0) {
}
}
object(MongoDB\Model\CollectionInfo)#3 (2) {
["name"]=>
string(6) "restos"
["options"]=>
array(0) {
}
}
See Also
--------
- :phpmethod:`MongoDB\Database::listCollectionNames()`
- :manual:`listCollections </reference/command/listCollections>` command
reference in the MongoDB manual
- `Enumerating Collections
<https://github.com/mongodb/specifications/blob/master/source/enumerate-collections/enumerate-collections.md>`_
specification