public function Tools::listCollections in MongoDB 8.2
List collections matching $regex in database $alias.
Parameters
string $alias: The alias in which to list the collections.
string $regex: The pattern collection names must match.
Return value
array An array of collection objects.
File
- modules/
mongodb/ src/ Install/ Tools.php, line 107
Class
- Tools
- Class MongoDbCommands provides the Drush commands for the mongodb module.
Namespace
Drupal\mongodb\InstallCode
public function listCollections(string $alias, string $regex) : array {
/** @var \MongoDB\Database $database */
$database = $this->dbFactory
->get($alias);
$collections = [];
foreach ($database
->listCollections() as $info) {
$name = $info
->getName();
$collection = $database
->selectCollection($name);
if (preg_match($regex, $name)) {
$collections[] = $collection;
}
}
return $collections;
}