original_string: public function findOneAndReplace($filter, $replacement, 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;
          }
  
          if ( ! isset($options['typeMap'])) {
              $options['typeMap'] = $this->typeMap;
          }
  
          $operation = new FindOneAndReplace($this->databaseName, $this->collectionName, $filter, $replacement, $options);
  
          return $operation->execute($server);
      }
code: public function findOneAndReplace($filter, $replacement, 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;
          }
  
          if ( ! isset($options['typeMap'])) {
              $options['typeMap'] = $this->typeMap;
          }
  
          $operation = new FindOneAndReplace($this->databaseName, $this->collectionName, $filter, $replacement, $options);
  
          return $operation->execute($server);
      }
code_tokens: public function findOneAndReplace ( $ filter , $ replacement , 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 ; } if ( ! isset ( $ options [ 'typeMap' ] ) ) { $ options [ 'typeMap' ] = $ this -> typeMap ; } $ operation = new FindOneAndReplace ( $ this -> databaseName , $ this -> collectionName , $ filter , $ replacement , $ options ) ; return $ operation -> execute ( $ server ) ; }
docstring: 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.
  
  @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 array|object|null
  @throws UnexpectedValueException if the command response was malformed
  @throws UnsupportedException if options are not supported by the selected server
  @throws InvalidArgumentException for parameter/option parsing errors
  @throws DriverRuntimeException for other driver errors (e.g. connection errors)
docstring_tokens: Finds a single document and replaces it returning either the original or the replaced document .