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.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. sort array|objectSpecify which document the operation updates if the query matches multiple documents. The first document matched by the sort order will be updated. 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::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::replaceOneMongoDB\Driver\BulkWriteCommand::updateManyMongoDB\Driver\Manager::executeBulkWriteCommandMongoDB\Driver\BulkWriteCommandResult