/**
* Finds a single document and deletes it, returning the original.
*
* The document to return may be null if no document matched the filter.
*
* Note: BSON deserialization of the returned document does not yet support
* a custom type map (depends on: https://jira.mongodb.org/browse/PHPC-314).
*
* @see FindOneAndDelete::__construct() for supported options
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
*
* @param array|object $filter Query by which to filter documents
* @param array $options Command options
*
* @return object|null
*/
public function findOneAndDelete($filter, array $options = [])
{
$server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
if (!isset($options['writeConcern']) && Functions::serverSupportsFeature($server, self::$wireVersionForFindAndModifyWriteConcern)) {
$options['writeConcern'] = $this->writeConcern;
}
$operation = new FindOneAndDelete($this->databaseName, $this->collectionName, $filter, $options);
return $operation->execute($server);
}