class MongoUpdateBatch extends MongoWriteBatch (View source)

Constants

COMMAND_INSERT

COMMAND_UPDATE

COMMAND_DELETE

Methods

__construct(MongoCollection $collection, array $write_options)

(PECL mongo >= 1.5.0)

MongoUpdateBatch constructor.

bool
add(array $item)

(PECL mongo >= 1.5.0)

Adds a write operation to a batch

array
execute(array $write_options)

(PECL mongo >= 1.5.0)

Executes a batch of write operations

Details

__construct(MongoCollection $collection, array $write_options)

(PECL mongo >= 1.5.0)

MongoUpdateBatch constructor.

Parameters

MongoCollection $collection

The {\MongoCollection} to execute the batch on. Its https://php.net/manual/en/mongo.writeconcerns.php write concern will be copied and used as the default write concern if none is given as $write_options``` or during {\MongoWriteBatch::execute()}.

array $write_options

[optional]

An array of Write Options.

keyvalue meaning
w (int|string)https://php.net/manual/en/mongo.writeconcerns.php Write concern value
wtimeout (int)https://php.net/manual/en/mongo.writeconcerns.php Maximum time to wait for replication
orderedDetermins if MongoDB must apply this batch in order (sequentally, one item at a time) or can rearrange it. Defaults to ```TRUE```
j (bool)Wait for journaling on the primary. This value is discouraged, use WriteConcern instead
fsync (bool)Wait for fsync on the primary. This value is discouraged, use WriteConcern instead

bool add(array $item)

(PECL mongo >= 1.5.0)

Adds a write operation to a batch

Parameters

array $item

An array that describes a write operation. The structure of this value depends on the batch's operation type.

Batch type Argument expectation
```MongoWriteBatch::COMMAND_INSERT``` The document to add.
```MongoWriteBatch::COMMAND_UPDATE```

Raw update operation.

Required keys are "q" and "u", which correspond to the ```$criteria``` and ```$new_object``` parameters of {[\MongoCollection::update()},](MongoCollection.html) respectively.

Optional keys are "multi" and "upsert", which correspond to the "multiple" and "upsert" options for {[\MongoCollection::update()},](MongoCollection.html) respectively. If unspecified, both options default to ```FALSE```.

```MongoWriteBatch::COMMAND_DELETE```

Raw delete operation.

Required keys are: "q" and "limit", which correspond to the ```$criteria``` parameter and "justOne" option of {[\MongoCollection::remove()},](MongoCollection.html) respectively.

The "limit" option is an integer; however, MongoDB only supports 0 (i.e. remove all matching ocuments) and 1 (i.e. remove at most one matching document) at this time.

Return Value

bool

Returns TRUE on success and throws an exception on failure.

final array execute(array $write_options)

(PECL mongo >= 1.5.0)

Executes a batch of write operations

Parameters

array $write_options

See {\MongoWriteBatch::__construct}

Return Value

array

Returns an array containing statistical information for the full batch. If the batch had to be split into multiple batches, the return value will aggregate the values from individual batches and return only the totals. If the batch was empty, an array containing only the 'ok' field is returned (as TRUE) although nothing will be shipped over the wire (NOOP).