|
The MongoDB\Driver\BulkWriteCommand classはじめにMongoDB\Driver\BulkWriteCommand collects one or more write operations that should be sent to the server using the » bulkWrite command introduced in MongoDB 8.0. After adding any number of insert, update, and delete operations, the command may be executed via MongoDB\Driver\Manager::executeBulkWriteCommand. Unlike MongoDB\Driver\BulkWrite, where all write operations must target the same collection, each write operation within MongoDB\Driver\BulkWriteCommand may target a different collection. 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\BulkWriteCommand
final
class MongoDB\Driver\BulkWriteCommand
implements
Countable {
/* メソッド */
public __construct(arraynull
$options = null )public int count()
public void deleteMany(string
$namespace , arrayobject $filter , arraynull $options = null )public void deleteOne(string
$namespace , arrayobject $filter , arraynull $options = null )public mixed insertOne(string
$namespace , arrayobject $document )public void replaceOne(
string $namespace ,arrayobject $filter ,arrayobject $replacement ,arraynull $options = null ) public void updateMany(
string $namespace ,arrayobject $filter ,arrayobject $update ,arraynull $options = null ) public void updateOne(
}string $namespace ,arrayobject $filter ,arrayobject $update ,arraynull $options = null ) 例例1 Mixed write operations Mixed write operations (i.e. inserts, updates, and deletes) will be sent to the server using a single » bulkWrite command.
上の例の出力は以下となります。 Inserted 3 document(s) Updated 1 document(s) 例2 Ordered write operations causing an error
上の例の出力は、 たとえば以下のようになります。 array(1) { [3]=> object(MongoDB\Driver\WriteError)#5 (4) { ["message"]=> string(78) "E11000 duplicate key error collection: db.coll index: _id_ dup key: { _id: 1 }" ["code"]=> int(11000) ["index"]=> int(3) ["info"]=> object(stdClass)#6 (0) { } } } Inserted 2 document(s) 参考
|