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

MongoDB\Driver\BulkWriteCommand::updateOne

PHP function Edit on GitHub ✎

(mongodb >=2.1.0)

Add an updateOne operation

Description

MongoDB\Driver\BulkWriteCommand::updateOne(string $namespace, array|object $filter, array|object $update, array|null $options = null): void

Add an updateOne operation to the MongoDB\Driver\BulkWriteCommand. The first document 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.
sortarray|objectSpecify which document the operation updates if the query matches multiple documents. The first document matched by the sort order will be updated.
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::updateOne() example

php
<?php

$manager = new MongoDB\Driver\Manager;

$bulk = new MongoDB\Driver\BulkWriteCommand;
$bulk->updateOne('db.coll', ['x' => 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/updateone.xml · from the official PHP manual (php/doc-en)