|
The MongoDB\Driver\BulkWrite classはじめにThe MongoDB\Driver\BulkWrite collects one or more write operations that should be sent to the server. After adding any number of insert, update, and delete operations, the collection may be executed via MongoDB\Driver\Manager::executeBulkWrite. Write operations may either be ordered (default) or unordered. Ordered write operations are sent to the server, in the order provided, for serial execution. If a write fails, any remaining operations will be aborted. Unordered operations are sent to the server in an arbitrary order where they may be executed in parallel. Any errors that occur are reported after all operations have been attempted. クラス概要MongoDB\Driver\BulkWrite
final
class MongoDB\Driver\BulkWrite
implements
Countable {
/* メソッド */
public __construct(arraynull
$options = null )public int count()
public void delete(arrayobject
$filter , arraynull $deleteOptions = null )public mixed insert(arrayobject
$document )public void update(arrayobject
}$filter , arrayobject $newObj , arraynull $updateOptions = null )例例1 Mixed write operations are grouped by type Mixed write operations (i.e. inserts, updates, and deletes) will be assembled into typed write commands to be sent sequentially to the server.
Will result in four write commands (i.e. roundtrips) being executed. Since the operations are ordered, the third insertion cannot be sent until the preceding update is executed. 例2 Ordered write operations causing an error
上の例の出力は以下となります。 Operation#7: E11000 duplicate key error index: db.collection.$_id_ dup key: { : 3 } (11000) Inserted 4 document(s) Updated 2 document(s) If the write concern could not be fullfilled, the example above would output something like: waiting for replication timed out (64): array ( 'wtimeout' => true, ) Operation#7: E11000 duplicate key error index: databaseName.collectionName.$_id_ dup key: { : 3 } (11000) Inserted 4 document(s) Updated 2 document(s) If we execute the example above, but allow for unordered writes:
上の例の出力は以下となります。 Operation#7: E11000 duplicate key error index: db.collection.$_id_ dup key: { : 3 } (11000) Operation#8: E11000 duplicate key error index: db.collection.$_id_ dup key: { : 4 } (11000) Inserted 5 document(s) Updated 2 document(s) 参考
|