public function update($entity, array $options = []): bool
    {
        if (false === $this->fireEvent('updating', $entity, true)) {
            return false;
        }

        if (!$entity->_id) {
            if ($result = $this->insert($entity, $options, false)) {
                $this->afterSuccess($entity);

                $this->fireEvent('updated', $entity);
            }

            return $result;
        }

        $data = $this->parseToDocument($entity);

        $queryResult = $this->getCollection()->updateOne(
            ['_id' => $data['_id']],
            ['$set' => $data],
            $this->mergeOptions($options)
        );

        $result = $queryResult->isAcknowledged() && $queryResult->getModifiedCount();

        if ($result) {
            $this->afterSuccess($entity);

            $this->fireEvent('updated', $entity);
        }

        return $result;
    }