Unable to connect to more than one MongoDB nodes of a replica set using Private endpoint aware URL from GCP

Summary

Unable to connect to multiple MongoDB nodes of a replica set using Private endpoint aware URL from GCP using Java driver

Java Driver Version

mongodb-driver-sync 4.6.0

Description

When trying to connect to Atlas Mongo from GCP using Private Endpoint (Dedicated Cluster) using Java driver, the connection is not established when more than one private endpoint aware MongoDB instance address in the replica set is provided. That is the following code

ConnectionString connectionString = new ConnectionString(“mongodb://admin:admin@pl-00-000-asia-south1-gcp.sb9fh.mongodb.net:27017,pl-00-001-asia-south1-gcp.sb9fh.mongodb.net:27017,pl-00-012-asia-south1-gcp.sb9fh.mongodb.net:27017/?ssl=true&authSource=admin&retryWrites=true&w=majority”);
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase(“src”);

results in the error

{{Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@3e7a23e5. Client view of cluster state is {type=REPLICA_SET, servers=[
{address=pl-00-000-asia-south1-gcp.sb9fh.mongodb.net:27017 type=UNKNOWN, state=CONNECTING}
, {address=pl-00-001-asia-south1-gcp.sb9fh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, {address=pl-00-012-asia-south1-gcp.sb9fh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}]}}

whereas, by providing only one private endpoint aware host address (as shown below) the connection can be established.

ConnectionString connectionString = new ConnectionString(“mongodb://admin:admin@pl-00-000-asia-south1-gcp.sb9fh.mongodb.net:27017?ssl=true&authSource=admin&retryWrites=true&w=majority”);

But the Mongo shell is able to connect when multiple private endpoint aware MongoDB node addresses are given,

mongosh "mongodb://admin:admin@pl-00-000-asia-south1-gcp.sb9fh.mongodb.net:27017,pl-00-001-asia-south1-gcp.sb9fh.mongodb.net:27017,pl-00-012-asia-south1-gcp.sb9fh.mongodb.net:27017" --username admin

  • Why does the Java driver fail to connect, with a TimeoutException, to the replicaset when more than one private endpoint aware host is provided, but connects when only one is provided?
  • Shouldn’t Java driver be capable of connecting to the shard (or replica set) given that the mongo shell is able to do the same?
  • Is there a way to connect to the MongoDB instance nodes (port - 27017) using private aware endpoints through Java driver?

Note: Using mongodb+srv:// is not an option for the current requirement.