def METHOD_NAME(self):
    self.logger.debug('Getting server info.')
    server_info = pymongo.MongoClient(self.host, self.port).server_info()
    server_version = server_info['version']
    server_version_split = tuple(server_version.split('.'))
    self.logger.debug('Connecting to MongoDB server version %s.',
                      server_version)
    try:
        if self.pymongo_35 and self.username and server_version_split >= ('3', '4'):
            self._client = pymongo.MongoClient(self.host,
                                               self.port,
                                               username=self.username,
                                               password=self.password)
        else:
            self._client = pymongo.MongoClient(self.host,
                                               self.port)
    except pymongo.errors.ConnectionFailure:
        raise ValueError('Connection to MongoDB server failed.')
    else:
        db = self._client[self.database]
        if self.username and not self.pymongo_35 or server_version_split < ('3', '4'):
            self.logger.debug('Trying to authenticate to database %s.',
                              self.database)
            try:
                db.authenticate(name=self.db_user,
                                password=self.db_pass)
            except pymongo.errors.OperationFailure:
                raise ValueError(f'Authentication to database {self.database} failed')
        self._collection = db[self.collection]
        self.logger.info('Successfully connected to MongoDB server.')