[JAVA-4769] Unable to connect to more than one MongoDB nodes of a replica set using Private endpoint aware URL from GCP Created: 12/Oct/22  Updated: 27/Oct/23  Resolved: 08/Nov/22

Status: Closed
Project: Java Driver
Component/s: Connection Management, Connection String
Affects Version/s: 4.6.0
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Ajay Mathias Assignee: Jeffrey Yemin
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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”);

Whereas, 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.



 Comments   
Comment by PM Bot [ 08/Nov/22 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Anna Henningsen [ 25/Oct/22 ]

Can you post a comment with the full mongosh output

I think in particular a log file from a relevant mongosh session (https://www.mongodb.com/docs/mongodb-shell/logs/) would be helpful.

Comment by Jeffrey Yemin [ 20/Oct/22 ]

ajay.mathias@webaction.com can you also post the output of running rs.status() in mongosh after you connect?

Comment by Jeffrey Yemin [ 20/Oct/22 ]

ajay.mathias@webaction.com, the difference in behavior with mongosh is definitely interesting. Can you post a comment with the full mongosh output, so we can see what operations you're able to perform with mongosh? i.e. are you able to connect and then successfully execute a CRUD operation?

Comment by Ajay Mathias [ 20/Oct/22 ]

I have gone through the documentation and as suggested I have also posted this query on the community portal.

But I still think that this could be a Java driver issue because of two reasons

  • The connection can be established from mongosh by giving all three private endpoint aware host addresses, but not from Java driver.
  • The Java driver is able to establish the connection if only one of the host address is given, but not all three.
Comment by Jeffrey Yemin [ 14/Oct/22 ]

Hi there, thank you for reaching out. This sounds like a support issue, so I wanted to give you some resources to get this question answered more quickly:

  • Our MongoDB support portal, located at support.mongodb.com
  • Our MongoDB community portal, located here
  • If you are an Atlas customer, you can also: Click the in-app chat icon in the lower right corner to chat with a MongoDB Support representative OR Click Support in the left-hand navigation to view Developer Resources.

Just in case you have already opened a support case and are not receiving sufficient help, please let me know and I can facilitate escalating your issue.

Thank you!

Generated at Thu Feb 08 09:02:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.