php8.5
Home/ Manual/ driver / bulkwritecommand/ MongoDB\Driver\BulkWriteCommand::updateMany

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.

options
OptionTypeDescriptionDefault
arrayFiltersarrayAn 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.
hintstring|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.
upsertboolIf filter does not match an existing document, insert a single document. The document will be created by applying operators in update to any field values in filter.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::replaceOne
  • MongoDB\Driver\BulkWriteCommand::updateMany
  • MongoDB\Driver\Manager::executeBulkWriteCommand
  • MongoDB\Driver\BulkWriteCommandResult

Source: reference/mongodb/mongodb/driver/bulkwritecommand/updatemany.xml · from the official PHP manual (php/doc-en)