Connecting ATLAS Serverless using Java and DNS txt record issue

Trying to connect Atlas server less database using below proposed connection string:

mongodb+srv://USER_NAME:PASSWORD@MONGO_CLUSTER.6zmxa.mongodb.net/MONGO_DATABASE?retryWrites=true&w=majority;

getting below exception

A TXT record is only permitted to contain the keys [authsource, replicaset], but the TXT record for ‘serverlessinstance0.6zmxa.mongodb.net’ contains the keys [loadbalanced, authsource]

POM.xml

org.mongodb mongodb-driver-sync 4.5.0

Code

ConnectionString connectionString = new ConnectionString(MONGO_URL);
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.applyToSslSettings(builder →
builder.enabled(true))
.serverApi(ServerApi.builder()
.version(ServerApiVersion.V1)
.build())
.build();

		MongoClient mongoClient = MongoClients.create(settings);

any help would be highly appreciated

Hi @Lakshmi_Narayana ,

You probably took this code from the Atlas UI,

If you look in the quick guide documentation you can have a simpler connection which works fine for me:

  String uri = "mongodb+srv://<username>:<password>@serverless1.abcde.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
    MongoClient mongoClient = MongoClients.create(uri) ;
         MongoDatabase database = mongoClient.getDatabase("test");

thanks
Pavel

1 Like

I suspect you have a conflict somewhere in your build configuration and you’re loading classes from a previous release of the driver. Check for older releases of either mongodb-driver-core or mongo-java-driver, and exclude them.

2 Likes

thanks. Issue resolved.