public function save(&$a, array $options = [])
    {
        $id = $this->ensureDocumentHasMongoId($a);

        $document = (array) $a;

        $options['upsert'] = true;

        try {
            /** @var \MongoDB\UpdateResult $result */
            $result = $this->collection->replaceOne(
                TypeConverter::fromLegacy(['_id' => $id]),
                TypeConverter::fromLegacy($document),
                $this->convertWriteConcernOptions($options)
            );

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

            $resultArray = [
                'ok' => 1.0,
                'nModified' => $result->getModifiedCount(),
                'n' => $result->getUpsertedCount() + $result->getModifiedCount(),
                'err' => null,
                'errmsg' => null,
                'updatedExisting' => $result->getUpsertedCount() == 0 && $result->getModifiedCount() > 0,
            ];
            if ($result->getUpsertedId() !== null) {
                $resultArray['upserted'] = TypeConverter::toLegacy($result->getUpsertedId());
            }

            return $resultArray;
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            throw ExceptionConverter::toLegacy($e);
        }
    }