See Release Notes
Long Term Support Release
Differences Between: [Versions 311 and 401] [Versions 400 and 401]
1 <?php 2 /* 3 * Copyright 2020-present MongoDB, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * https://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 namespace MongoDB\Operation; 19 20 use ArrayIterator; 21 use Iterator; 22 use MongoDB\Command\ListDatabases as ListDatabasesCommand; 23 use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; 24 use MongoDB\Driver\Server; 25 use MongoDB\Exception\InvalidArgumentException; 26 use MongoDB\Exception\UnexpectedValueException; 27 28 use function array_column; 29 30 /** 31 * Operation for the ListDatabases command, returning only database names. 32 * 33 * @api 34 * @see \MongoDB\Client::listDatabaseNames() 35 * @see https://mongodb.com/docs/manual/reference/command/listDatabases/#mongodb-dbcommand-dbcmd.listDatabases 36 */ 37 class ListDatabaseNames implements Executable 38 { 39 /** @var ListDatabasesCommand */ 40 private $listDatabases; 41 42 /** 43 * Constructs a listDatabases command. 44 * 45 * Supported options: 46 * 47 * * authorizedDatabases (boolean): Determines which databases are returned 48 * based on the user privileges. 49 * 50 * For servers < 4.0.5, this option is ignored. 51 * 52 * * comment (mixed): BSON value to attach as a comment to this command. 53 * 54 * This is not supported for servers versions < 4.4. 55 * 56 * * filter (document): Query by which to filter databases. 57 * 58 * * maxTimeMS (integer): The maximum amount of time to allow the query to 59 * run. 60 * 61 * * session (MongoDB\Driver\Session): Client session. 62 * 63 * @param array $options Command options 64 * @throws InvalidArgumentException for parameter/option parsing errors 65 */ 66 public function __construct(array $options = []) 67 { 68 $this->listDatabases = new ListDatabasesCommand(['nameOnly' => true] + $options); 69 } 70 71 /** 72 * Execute the operation. 73 * 74 * @see Executable::execute() 75 * @throws UnexpectedValueException if the command response was malformed 76 * @throws DriverRuntimeException for other driver errors (e.g. connection errors) 77 */ 78 public function execute(Server $server): Iterator 79 { 80 $result = $this->listDatabases->execute($server); 81 82 return new ArrayIterator(array_column($result, 'name')); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body