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

MongoDB\Driver\BulkWriteCommand::deleteOne

PHP function Edit on GitHub ✎

(mongodb >=2.1.0)

Add a deleteOne operation

Description

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

Add a deleteOne operation to the MongoDB\Driver\BulkWriteCommand. The first document matching filter in the collection identified by namespace will be deleted.

Parameters

options
OptionTypeDescriptionDefault
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.

Return Values

Void

Errors/Exceptions

Examples

MongoDB\Driver\BulkWriteCommand::deleteOne() example

php
<?php

$manager = new MongoDB\Driver\Manager;

$bulk = new MongoDB\Driver\BulkWriteCommand;
$bulk->deleteOne('db.coll', ['x' => 1]);

$result = $manager->executeBulkWriteCommand($bulk);

?>

See Also

  • MongoDB\Driver\BulkWriteCommand::deleteMany
  • MongoDB\Driver\Manager::executeBulkWriteCommand
  • MongoDB\Driver\BulkWriteCommandResult

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