Failed looking up TXT record for host myatlasclusteredu.qvrwtm7.mongodb.net

Hi all, I’m having a little difficulty connecting to my Atlas database using Java.

this is the driver that i’m importing via Maven

<dependencies>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-sync</artifactId>
            <version>5.0.0</version>
        </dependency>
    </dependencies>

this is the code for the java class

package org.example;

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.ServerApi;
import com.mongodb.ServerApiVersion;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;

public class Main {
    public static void main(String[] args) {
        ConnectionString connectionString = new ConnectionString("mongodb+srv://testUser:test123456@myatlasclusteredu.qvrwtm7.mongodb.net/?retryWrites=true&w=majority&appName=myAtlasClusterEDU");
        MongoClientSettings settings = MongoClientSettings.builder()
                .applyConnectionString(connectionString)
                .serverApi(ServerApi.builder()
                        .version(ServerApiVersion.V1)
                        .build())
                .build();

        MongoClient mongoClient = MongoClients.create(settings);
    }
}

(I already tried to follow the steps on atlas and also on [View MongoDB Java Driver installation instructions.] but nothing worked.)

When i run the code, this is the error that im getting

Mar 10, 2024, 7:21:12 PM com.mongodb.internal.diagnostics.logging.Loggers shouldUseSLF4J
Warning: SLF4J is not found on the classpath.  Logging is disabled for the 'org.mongodb.driver' component
Exception in thread "main" com.mongodb.MongoConfigurationException: Failed looking up TXT record for host myatlasclusteredu.qvrwtm7.mongodb.net
	at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(DefaultDnsResolver.java:137)
	at com.mongodb.ConnectionString.<init>(ConnectionString.java:434)
	at com.mongodb.ConnectionString.<init>(ConnectionString.java:321)
	at org.example.Main.main(Main.java:12)
Caused by: com.mongodb.spi.dns.DnsException: DNS error
	at com.mongodb.internal.dns.JndiDnsClient.getResourceRecordData(JndiDnsClient.java:54)
	at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(DefaultDnsResolver.java:118)
	... 3 more
Caused by: javax.naming.CommunicationException: DNS error [Root exception is java.net.SocketTimeoutException: Receive timed out]; remaining name 'myatlasclusteredu.qvrwtm7.mongodb.net'
	at com.sun.jndi.dns.DnsClient.query(DnsClient.java:312)
	at com.sun.jndi.dns.Resolver.query(Resolver.java:81)
	at com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
	at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
	at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
	at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
	at javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:142)
	at com.mongodb.internal.dns.JndiDnsClient.getResourceRecordData(JndiDnsClient.java:41)
	... 4 more
Caused by: java.net.SocketTimeoutException: Receive timed out
	at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method)
	at java.net.DualStackPlainDatagramSocketImpl.receive0(DualStackPlainDatagramSocketImpl.java:124)
	at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:149)
	at java.net.DatagramSocket.receive(DatagramSocket.java:812)
	at com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:422)
	at com.sun.jndi.dns.DnsClient.query(DnsClient.java:211)
	... 11 more

Process finished with exit code 1

and running mongosh this is the error

>mongosh "mongodb+srv://myatlasclusteredu.qvrwtm7.mongodb.net/" --apiVersion 1 --username testUser
Enter password: **********
Current Mongosh Log ID: 65ee5db107acbe3496db21bb
Connecting to:          mongodb+srv://<credentials>@myatlasclusteredu.qvrwtm7.mongodb.net/?appName=mongosh+2.1.5
Error: queryTxt ETIMEOUT myatlasclusteredu.qvrwtm7.mongodb.net

I already tried with the Java SDK 21, 8, with the diver 5.0.0 and the 4.11.1 and nothing work, Im new on mongo and i like it but this error is driving me crazy.

Quick sanity check:

  1. Did you use the Network feature of Atlas to enable connections from your current IP address?
  2. Is there a typographical error in your mongodb+svr URI?
  3. Can you connect via mongosh or Mongodb Compass?
  4. Are you having firewall issues?
2 Likes

I was able to find out that a ineeded to setup Google’s dns on mi pc to get it work

1 Like

Excellent, good work.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.