public function update(array $criteria, array $newobj, array $options = [])
{
$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];
}