/**
* Update multiple documents
*
* @param \Sokil\Mongo\Expression|array|callable $expression expression to define
* which documents will change.
* @param \Sokil\Mongo\Operator|array|callable $updateData new data or operators to update
* @param array $options update options, see http://php.net/manual/ru/mongocollection.update.php
* @return \Sokil\Mongo\Collection
* @throws \Sokil\Mongo\Exception
*/
public function update($expression, $updateData, array $options = array())
{
// execute update operator
$result = $this->getMongoCollection()->update(Expression::convertToArray($expression), Operator::convertToArray($updateData), $options);
// if write concern acknowledged
if (is_array($result)) {
if ($result['ok'] != 1) {
throw new Exception(sprintf('Update error: %s: %s', $result['err'], $result['errmsg']));
}
return $this;
}
// if write concern unacknowledged
if (!$result) {
throw new Exception('Update error');
}
return $this;
}