|
7 | 7 | use MongoDB\Driver\Manager;
|
8 | 8 | use MongoDB\Driver\ReadPreference;
|
9 | 9 | use MongoDB\Driver\WriteConcern;
|
10 |
| -use MongoDB\Exception\UnexpectedValueException; |
11 | 10 | use MongoDB\Model\DatabaseInfoIterator;
|
12 |
| -use MongoDB\Model\DatabaseInfoLegacyIterator; |
| 11 | +use MongoDB\Operation\DropDatabase; |
| 12 | +use MongoDB\Operation\ListDatabases; |
13 | 13 |
|
14 | 14 | class Client
|
15 | 15 | {
|
@@ -37,45 +37,29 @@ public function __construct($uri, array $options = array(), array $driverOptions
|
37 | 37 | /**
|
38 | 38 | * Drop a database.
|
39 | 39 | *
|
40 |
| - * @see http://docs.mongodb.org/manual/reference/command/dropDatabase/ |
41 | 40 | * @param string $databaseName
|
42 |
| - * @return Cursor |
| 41 | + * @return object Command result document |
43 | 42 | */
|
44 | 43 | public function dropDatabase($databaseName)
|
45 | 44 | {
|
46 |
| - $databaseName = (string) $databaseName; |
47 |
| - $command = new Command(array('dropDatabase' => 1)); |
48 |
| - $readPreference = new ReadPreference(ReadPreference::RP_PRIMARY); |
| 45 | + $operation = new DropDatabase($databaseName); |
| 46 | + $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); |
49 | 47 |
|
50 |
| - return $this->manager->executeCommand($databaseName, $command, $readPreference); |
| 48 | + return $operation->execute($server); |
51 | 49 | }
|
52 | 50 |
|
53 | 51 | /**
|
54 | 52 | * List databases.
|
55 | 53 | *
|
56 |
| - * @see http://docs.mongodb.org/manual/reference/command/listDatabases/ |
| 54 | + * @see ListDatabases::__construct() for supported options |
57 | 55 | * @return DatabaseInfoIterator
|
58 |
| - * @throws UnexpectedValueException if the command result is malformed |
59 | 56 | */
|
60 |
| - public function listDatabases() |
| 57 | + public function listDatabases(array $options = array()) |
61 | 58 | {
|
62 |
| - $command = new Command(array('listDatabases' => 1)); |
| 59 | + $operation = new ListDatabases($options); |
| 60 | + $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); |
63 | 61 |
|
64 |
| - $cursor = $this->manager->executeCommand('admin', $command); |
65 |
| - $cursor->setTypeMap(array('document' => 'array')); |
66 |
| - $result = current($cursor->toArray()); |
67 |
| - |
68 |
| - if ( ! isset($result['databases']) || ! is_array($result['databases'])) { |
69 |
| - throw new UnexpectedValueException('listDatabases command did not return a "databases" array'); |
70 |
| - } |
71 |
| - |
72 |
| - /* Return an Iterator instead of an array in case listDatabases is |
73 |
| - * eventually changed to return a command cursor, like the collection |
74 |
| - * and index enumeration commands. This makes the "totalSize" command |
75 |
| - * field inaccessible, but users can manually invoke the command if they |
76 |
| - * need that value. |
77 |
| - */ |
78 |
| - return new DatabaseInfoLegacyIterator($result['databases']); |
| 62 | + return $operation->execute($server); |
79 | 63 | }
|
80 | 64 |
|
81 | 65 | /**
|
|
0 commit comments