public function update($criteria, $newobj, array $options = [])
    {
        $this->mustBeArrayOrObject($criteria);
        $this->mustBeArrayOrObject($newobj);

        $this->checkKeys((array) $newobj);

        $multiple = isset($options['multiple']) ? $options['multiple'] : false;
        $isReplace = ! \MongoDB\is_first_key_operator($newobj);

        if ($isReplace && $multiple) {
            throw new \MongoWriteConcernException('multi update only works with $ operators', 9);
        }
        unset($options['multiple']);

        $method = $isReplace ? 'replace' : 'update';
        $method .= $multiple ? 'Many' : 'One';

        try {
            /** @var \MongoDB\UpdateResult $result */
            $result = $this->collection->$method(
                TypeConverter::fromLegacy($criteria),
                TypeConverter::fromLegacy($newobj),
                $this->convertWriteConcernOptions($options)
            );
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            throw ExceptionConverter::toLegacy($e);
        }

        if (! $result->isAcknowledged()) {
            return true;
        }

        return [
            'ok' => 1.0,
            'nModified' => $result->getModifiedCount(),
            'n' => $result->getMatchedCount(),
            'err' => null,
            'errmsg' => null,
            'updatedExisting' => $result->getUpsertedCount() == 0 && $result->getModifiedCount() > 0,
        ];
    }
public function update($criteria, $newobj, array $options = [])
    {
        $this->mustBeArrayOrObject($criteria);
        $this->mustBeArrayOrObject($newobj);

        $this->checkKeys((array) $newobj);

        $multiple = isset($options['multiple']) ? $options['multiple'] : false;
        $isReplace = ! \MongoDB\is_first_key_operator($newobj);

        if ($isReplace && $multiple) {
            throw new \MongoWriteConcernException('multi update only works with $ operators', 9);
        }
        unset($options['multiple']);

        $method = $isReplace ? 'replace' : 'update';
        $method .= $multiple ? 'Many' : 'One';

        try {
            /** @var \MongoDB\UpdateResult $result */
            $result = $this->collection->$method(
                TypeConverter::fromLegacy($criteria),
                TypeConverter::fromLegacy($newobj),
                $this->convertWriteConcernOptions($options)
            );
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            throw ExceptionConverter::toLegacy($e);
        }

        if (! $result->isAcknowledged()) {
            return true;
        }

        return [
            'ok' => 1.0,
            'nModified' => $result->getModifiedCount(),
            'n' => $result->getMatchedCount(),
            'err' => null,
            'errmsg' => null,
            'updatedExisting' => $result->getUpsertedCount() == 0 && $result->getModifiedCount() > 0,
        ];
    }
public function update ( $ criteria , $ newobj , array $ options = [ ] ) { $ this -> mustBeArrayOrObject ( $ criteria ) ; $ this -> mustBeArrayOrObject ( $ newobj ) ; $ this -> checkKeys ( ( array ) $ newobj ) ; $ multiple = isset ( $ options [ 'multiple' ] ) ? $ options [ 'multiple' ] : false ; $ isReplace = ! \ MongoDB \ is_first_key_operator ( $ newobj ) ; if ( $ isReplace && $ multiple ) { throw new \ MongoWriteConcernException ( 'multi update only works with $ operators' , 9 ) ; } unset ( $ options [ 'multiple' ] ) ; $ method = $ isReplace ? 'replace' : 'update' ; $ method .= $ multiple ? 'Many' : 'One' ; try { /** @var \MongoDB\UpdateResult $result */ $ result = $ this -> collection -> $ method ( TypeConverter :: fromLegacy ( $ criteria ) , TypeConverter :: fromLegacy ( $ newobj ) , $ this -> convertWriteConcernOptions ( $ options ) ) ; } catch ( \ MongoDB \ Driver \ Exception \ Exception $ e ) { throw ExceptionConverter :: toLegacy ( $ e ) ; } if ( ! $ result -> isAcknowledged ( ) ) { return true ; } return [ 'ok' => 1.0 , 'nModified' => $ result -> getModifiedCount ( ) , 'n' => $ result -> getMatchedCount ( ) , 'err' => null , 'errmsg' => null , 'updatedExisting' => $ result -> getUpsertedCount ( ) == 0 && $ result -> getModifiedCount ( ) > 0 , ] ; }
Update records based on a given criteria

@link http://www.php.net/manual/en/mongocollection.update.php
@param array|object $criteria Description of the objects to update.
@param array|object $newobj The object with which to update the matching records.
@param array $options
@return bool|array
@throws MongoException
@throws MongoWriteConcernException
Update records based on a given criteria