Skip to content

Commit 081fc24

Browse files
committed
Merge pull request #758
2 parents 9477aef + e937569 commit 081fc24

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
====================================
2+
MongoDB\\Client::listDatabaseNames()
3+
====================================
4+
5+
.. versionadded:: 1.7
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
Definition
16+
----------
17+
18+
.. phpmethod:: MongoDB\\Client::listDatabaseNames()
19+
20+
Returns names for all databases on the server.
21+
22+
.. code-block:: php
23+
24+
function listDatabaseNames(array $options = []): Iterator
25+
26+
This method has the following parameters:
27+
28+
.. include:: /includes/apiargs/MongoDBClient-method-listDatabases-param.rst
29+
30+
The ``$options`` parameter supports the following options:
31+
32+
.. include:: /includes/apiargs/MongoDBClient-method-listDatabases-option.rst
33+
34+
Return Values
35+
-------------
36+
37+
An :php:`Iterator <class.iterator.php>`, which provides the name of each
38+
database on the server.
39+
40+
Errors/Exceptions
41+
-----------------
42+
43+
.. include:: /includes/extracts/error-unexpectedvalueexception.rst
44+
.. include:: /includes/extracts/error-invalidargumentexception.rst
45+
.. include:: /includes/extracts/error-driver-runtimeexception.rst
46+
47+
Example
48+
-------
49+
50+
The following example lists all databases on the server:
51+
52+
.. code-block:: php
53+
54+
<?php
55+
56+
$client = new MongoDB\Client;
57+
58+
foreach ($client->listDatabaseNames() as $databaseName) {
59+
var_dump($databaseName);
60+
}
61+
62+
The output would then resemble::
63+
64+
string(5) "local"
65+
string(4) "test"
66+
67+
See Also
68+
--------
69+
70+
- :phpmethod:`MongoDB\\Database::listDatabases()`
71+
- :manual:`listDatabases </reference/command/listDatabases>` command reference
72+
in the MongoDB manual
73+
- `Enumerating Databases
74+
<https://github.com/mongodb/specifications/blob/master/source/enumerate-databases.rst>`_
75+
specification

source/reference/method/MongoDBClient-listDatabases.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,9 @@ The output would then resemble::
8080
See Also
8181
--------
8282

83+
- :phpmethod:`MongoDB\\Database::listDatabaseNames()`
8384
- :manual:`listDatabases </reference/command/listDatabases>` command reference
8485
in the MongoDB manual
86+
- `Enumerating Databases
87+
<https://github.com/mongodb/specifications/blob/master/source/enumerate-databases.rst>`_
88+
specification
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
========================================
2+
MongoDB\\Database::listCollectionNames()
3+
========================================
4+
5+
.. versionadded:: 1.7
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
Definition
16+
----------
17+
18+
.. phpmethod:: MongoDB\\Database::listCollectionNames()
19+
20+
Returns names for all collections in this database.
21+
22+
.. code-block:: php
23+
24+
function listCollectionNames(array $options = []): Iterator
25+
26+
This method has the following parameters:
27+
28+
.. include:: /includes/apiargs/MongoDBDatabase-method-listCollections-param.rst
29+
30+
The ``$options`` parameter supports the following options:
31+
32+
.. include:: /includes/apiargs/MongoDBDatabase-method-listCollections-option.rst
33+
34+
Return Values
35+
-------------
36+
37+
An :php:`Iterator <class.iterator.php>`, which provides the name of each
38+
collection in the database.
39+
40+
Example
41+
-------
42+
43+
The following example lists all of the collections in the ``test`` database:
44+
45+
.. code-block:: php
46+
47+
<?php
48+
49+
$database = (new MongoDB\Client)->test;
50+
51+
foreach ($database->listCollectionNames() as $collectionName) {
52+
var_dump($collectionName);
53+
}
54+
55+
The output would then resemble::
56+
57+
string(11) "restaurants"
58+
string(5) "users"
59+
string(6) "restos"
60+
61+
The following example lists all collections whose name starts with ``"rest"``
62+
in the ``test`` database:
63+
64+
.. code-block:: php
65+
66+
<?php
67+
68+
$database = (new MongoDB\Client)->test;
69+
70+
$collections = $database->listCollectionNames([
71+
'filter' => [
72+
'name' => new MongoDB\BSON\Regex('^rest.*'),
73+
],
74+
]);
75+
76+
foreach ($collections as $collectionName) {
77+
var_dump($collectionName);
78+
}
79+
80+
The output would then resemble::
81+
82+
string(11) "restaurants"
83+
string(6) "restos"
84+
85+
.. note::
86+
87+
When enumerating collection names, a filter expression can only filter based
88+
on a collection's name and type. No other fields are available.
89+
90+
See Also
91+
--------
92+
93+
- :phpmethod:`MongoDB\\Database::listCollections()`
94+
- :manual:`listCollections </reference/command/listCollections` command
95+
reference in the MongoDB manual
96+
- `Enumerating Collections
97+
<https://github.com/mongodb/specifications/blob/master/source/enumerate-collections.rst>`_
98+
specification

source/reference/method/MongoDBDatabase-listCollections.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ The output would then resemble::
114114
See Also
115115
--------
116116

117+
- :phpmethod:`MongoDB\\Database::listCollectionNames()`
117118
- :manual:`listCollections </reference/command/listCollections` command
118119
reference in the MongoDB manual
119120
- `Enumerating Collections

0 commit comments

Comments
 (0)