MongoDB\Driver\BulkWriteCommand::replaceOne
PHP function
Edit on GitHub ✎
(mongodb >=2.1.0)
Add a replaceOne operation
Description
MongoDB\Driver\BulkWriteCommand::replaceOne(string $namespace, array|object $filter, array|object $replacement, array|null $options = null): void
Add a replaceOne operation to the MongoDB\Driver\BulkWriteCommand. The first document matching filter in the collection identified by namespace will be replaced.
Parameters
replacement(array|object)A replacement document.
optionsOption Type Description Default 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 replaces if the query matches multiple documents. The first document matched by the sort order will be replaced. upsert boolIf filterdoes not match an existing document, insert a single document. The document will be created fromreplacement.false
Return Values
Void
Errors/Exceptions
Examples
MongoDB\Driver\BulkWriteCommand::replaceOne() example
php
<?php
$manager = new MongoDB\Driver\Manager;
$bulk = new MongoDB\Driver\BulkWriteCommand;
$bulk->replaceOne('db.coll', ['x' => 1], ['x' => 1, 'y' => 2]);
$result = $manager->executeBulkWriteCommand($bulk);
?>See Also
MongoDB\Driver\BulkWriteCommand::updateOneMongoDB\Driver\BulkWriteCommand::updateManyMongoDB\Driver\Manager::executeBulkWriteCommandMongoDB\Driver\BulkWriteCommandResult