|
18 | 18 | namespace MongoDB\Operation;
|
19 | 19 |
|
20 | 20 | use MongoDB\Driver\Command;
|
21 |
| -use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; |
| 21 | +use MongoDB\Driver\Exception\CommandException; |
22 | 22 | use MongoDB\Driver\Server;
|
23 | 23 | use MongoDB\Driver\Session;
|
24 | 24 | use MongoDB\Driver\WriteConcern;
|
|
38 | 38 | */
|
39 | 39 | class DropCollection implements Executable
|
40 | 40 | {
|
| 41 | + /** @var integer */ |
| 42 | + private static $errorCodeNamespaceNotFound = 26; |
| 43 | + |
41 | 44 | /** @var string */
|
42 | 45 | private static $errorMessageNamespaceNotFound = 'ns not found';
|
43 | 46 |
|
@@ -122,13 +125,13 @@ public function execute(Server $server)
|
122 | 125 |
|
123 | 126 | try {
|
124 | 127 | $cursor = $server->executeWriteCommand($this->databaseName, $command, $this->createOptions());
|
125 |
| - } catch (DriverRuntimeException $e) { |
| 128 | + } catch (CommandException $e) { |
126 | 129 | /* The server may return an error if the collection does not exist.
|
127 |
| - * Check for an error message (unfortunately, there isn't a code) |
128 |
| - * and NOP instead of throwing. |
129 |
| - */ |
130 |
| - if ($e->getMessage() === self::$errorMessageNamespaceNotFound) { |
131 |
| - return (object) ['ok' => 0, 'errmsg' => self::$errorMessageNamespaceNotFound]; |
| 130 | + * Check for an error code (or message for pre-3.2 servers) and |
| 131 | + * return the command reply instead of throwing. */ |
| 132 | + if ($e->getCode() === self::$errorCodeNamespaceNotFound || |
| 133 | + $e->getMessage() === self::$errorMessageNamespaceNotFound) { |
| 134 | + return $e->getResultDocument(); |
132 | 135 | }
|
133 | 136 |
|
134 | 137 | throw $e;
|
|
0 commit comments