public function insert(array $data, $options = [])
    {
        $maxRetries = $this->maxRetries;
        $tries = 0;

        // Check whether we're dealing with a batch insert.
        if (isset($data[0]) && is_array($data[0])) {
            // Insert using batchInsert
            do {
                try {
                    $result = $this->collection->batchInsert($data, $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);

            if (! $result || ! ($result === true || (bool) $result['ok'])) {
                return false;
            }

            $result = [];

            foreach ($data as $r) {
                // Collect all the id's for the return value
                $result[] = $r['_id'];
            }

            // Return all inserted id's.
            return $result;
        }

        do {
            try {
                $result = $this->collection->insert($data, $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);

        if ($result === true || (bool) $result['ok']) {
            return $data['_id'];
        }

        return false;
    }