I have used the following Java Code to connect to my mongoDB atlas cluster:
try(MongoClient mongoClient = MongoClients.create(GlobalVariables.connectionString