MongoDB\Driver\BulkWriteCommand::updateMany
PHP function
Edit on GitHub ✎
(mongodb >=2.1.0)
Add an updateMany operation
Description
MongoDB\Driver\BulkWriteCommand::updateMany(string $namespace, array|object $filter, array|object $update, array|null $options = null): void
Add an updateMany operation to the MongoDB\Driver\BulkWriteCommand. All documents matching filter in the collection identified by namespace will be updated.
Parameters
update(array|object)A document containing either update operators (e.g.
$set) or an aggregation pipeline.optionsOption Type Description Default arrayFilters arrayAn array of filter documents that determines which array elements to modify for an update operation on an array field. See Specify arrayFilters for Array Update Operations in the MongoDB manual for more information. hint string|array|objectIndex specification. Specify either the index name as a string or the index key pattern. If specified, then the query system will only consider plans using the hinted index. upsert boolIf filterdoes not match an existing document, insert a single document. The document will be created by applying operators inupdateto any field values infilter.false
Return Values
Void
Errors/Exceptions
Examples
MongoDB\Driver\BulkWriteCommand::updateMany() example
php
<?php
$manager = new MongoDB\Driver\Manager;
$bulk = new MongoDB\Driver\BulkWriteCommand;
$bulk->updateMany('db.coll', ['x' => ['$gt' => 1]], ['$set' => ['y' => 2]]);
$result = $manager->executeBulkWriteCommand($bulk);
?>See Also
MongoDB\Driver\BulkWriteCommand::replaceOneMongoDB\Driver\BulkWriteCommand::updateManyMongoDB\Driver\Manager::executeBulkWriteCommandMongoDB\Driver\BulkWriteCommandResult