|
24 | 24 | use MongoDB\Builder\BuilderEncoder; |
25 | 25 | use MongoDB\Builder\Pipeline; |
26 | 26 | use MongoDB\Codec\Encoder; |
| 27 | +use MongoDB\Driver\BulkWriteCommand; |
| 28 | +use MongoDB\Driver\BulkWriteCommandResult; |
27 | 29 | use MongoDB\Driver\ClientEncryption; |
28 | 30 | use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException; |
29 | 31 | use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; |
|
39 | 41 | use MongoDB\Model\BSONArray; |
40 | 42 | use MongoDB\Model\BSONDocument; |
41 | 43 | use MongoDB\Model\DatabaseInfo; |
| 44 | +use MongoDB\Operation\ClientBulkWriteCommand; |
42 | 45 | use MongoDB\Operation\DropDatabase; |
43 | 46 | use MongoDB\Operation\ListDatabaseNames; |
44 | 47 | use MongoDB\Operation\ListDatabases; |
@@ -189,6 +192,32 @@ final public function addSubscriber(Subscriber $subscriber): void |
189 | 192 | $this->manager->addSubscriber($subscriber); |
190 | 193 | } |
191 | 194 |
|
| 195 | + /** |
| 196 | + * Executes multiple write operations across multiple namespaces. |
| 197 | + * |
| 198 | + * @param BulkWriteCommand|ClientBulkWrite $bulk Assembled bulk write command or builder |
| 199 | + * @param array $options Additional options |
| 200 | + * @throws UnsupportedException if options are unsupported on the selected server |
| 201 | + * @throws InvalidArgumentException for parameter/option parsing errors |
| 202 | + * @throws DriverRuntimeException for other driver errors (e.g. connection errors) |
| 203 | + * @see ClientBulkWriteCommand::__construct() for supported options |
| 204 | + */ |
| 205 | + public function bulkWrite(BulkWriteCommand|ClientBulkWrite $bulk, array $options = []): BulkWriteCommandResult |
| 206 | + { |
| 207 | + if (! isset($options['writeConcern']) && ! is_in_transaction($options)) { |
| 208 | + $options['writeConcern'] = $this->writeConcern; |
| 209 | + } |
| 210 | + |
| 211 | + if ($bulk instanceof ClientBulkWrite) { |
| 212 | + $bulk = $bulk->bulkWriteCommand; |
| 213 | + } |
| 214 | + |
| 215 | + $operation = new ClientBulkWriteCommand($bulk, $options); |
| 216 | + $server = select_server_for_write($this->manager, $options); |
| 217 | + |
| 218 | + return $operation->execute($server); |
| 219 | + } |
| 220 | + |
192 | 221 | /** |
193 | 222 | * Returns a ClientEncryption instance for explicit encryption and decryption |
194 | 223 | * |
|
0 commit comments