/** * Finds a single document and deletes it, returning the original. * * The document to return may be null. * * 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']) && \MongoDB\server_supports_feature($server, self::$wireVersionForFindAndModifyWriteConcern)) { $options['writeConcern'] = $this->writeConcern; } $operation = new FindOneAndDelete($this->databaseName, $this->collectionName, $filter, $options); return $operation->execute($server); }
/** * Finds a single document and deletes it, returning the original. * * The document to return may be null. * * @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 = []) { $operation = new FindOneAndDelete($this->databaseName, $this->collectionName, $filter, $options); $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $operation->execute($server); }