/** * Finds a single document and replaces it, returning either the original or * the replaced document. * * The document to return may be null if no document matched the filter. By * default, the original document is returned. Specify * FindOneAndReplace::RETURN_DOCUMENT_AFTER for the "returnDocument" option * to return the updated document. * * 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 FindOneAndReplace::__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|object $replacement Replacement document * @param array $options Command options * * @return object|null */ public function findOneAndReplace($filter, $replacement, 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 FindOneAndReplace($this->databaseName, $this->collectionName, $filter, $replacement, $options); return $operation->execute($server); }