Esempio n. 1
0
 /**
  * Finds a single document and updates it, returning either the original or
  * the updated document.
  *
  * The document to return may be null. By default, the original document is
  * returned. Specify FindOneAndUpdate::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 $update  Update to apply to the matched document
  * @param array        $options Command options
  * @return object|null
  */
 public function findOneAndUpdate($filter, $update, 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 FindOneAndUpdate($this->databaseName, $this->collectionName, $filter, $update, $options);
     return $operation->execute($server);
 }
Esempio n. 2
0
 /**
  * Finds a single document and updates it, returning either the original or
  * the updated document.
  *
  * The document to return may be null. By default, the original document is
  * returned. Specify FindOneAndUpdate::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 $update  Update to apply to the matched document
  * @param array        $options Command options
  * @return object|null
  */
 public function findOneAndUpdate($filter, $update, array $options = [])
 {
     $operation = new FindOneAndUpdate($this->databaseName, $this->collectionName, $filter, $update, $options);
     $server = $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
     return $operation->execute($server);
 }