/** * Updates a collection * * @param mixed $values update query, array or callback * @param mixed $query update filter * @param array $options update options * * @return boolean query success */ public function update($values = [], $query = null, $options = []) { if ($values instanceof Closure) { $callback = $values; $values = new Query\Update(); $values->setOptions($options); $callback($values); } if ($values instanceof Query\Update) { $options = $values->getOptions(); $query = $values->getWhere(); $values = $values->getUpdate(); } if (!is_array($values) || !is_array($options)) { throw new \InvalidArgumentException('Update params $update and $options must be arrays.'); } isset($query) || ($query = []); $maxRetries = $this->maxRetries; $tries = 0; do { try { $result = $this->collection->update($query, $values, $options); break; } catch (MongoCursorException $e) { // Retry "save" in case of rediscovery latency issues // in replica set failover. Error codes 10107, 13435, and 10058 // are MongoCursorException's "not master" errors. if (in_array($e->getCode(), [10107, 13435, 10058])) { if ($tries === $maxRetries) { throw $e; } else { $tries++; continue; } } else { throw $e; } } } while ($tries <= $maxRetries); return $result === true || (bool) $result['ok']; }