MongoDB Connection Error while Syncing Two Databases in Spring Boot

Dear MongoDB Community,

I am encountering an error while attempting to sync two databases residing on separate servers using Spring Boot. The MongoDB versions for both databases are 5.0.1, and I am using OpenJDK version “1.8.0_362” with the following details:

OpenJDK Runtime Environment OpenJDK 64-Bit Server VM (build 25.362-b09, mixed mode)

To handle the database synchronization, I have included the following dependency in my project’s pom.xml:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.12.11</version> <!-- Replace with the version compatible with your project -->
</dependency>

However, when attempting to establish a connection, I encounter the following error message:
Error: No server chosen by com.mongodb.client.internal.MongoClientDelegate$1@3e120c13 from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address:27017=ac-rl8ettt-shard-00-02.4qgdyua.mongodb.net, type=UNKNOWN, state=CONNECTING}, ServerDescription{address:27017=ac-rl8ettt-shard-00-01.4qgdyua.mongodb.net, type=UNKNOWN, state=CONNECTING}, ServerDescription{address:27017=ac-rl8ettt-shard-00-00.4qgdyua.mongodb.net, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out.
I understand that the error is related to the MongoDB driver attempting to connect to the replica set. However, it seems unable to choose an appropriate server to connect to.

Can you please provide guidance on how to resolve this issue? Any insights into the root cause or potential solutions would be greatly appreciated. If you require any additional information to assist with troubleshooting, please let me know, and I’ll be happy to provide it.

Thank you for your time and assistance.

Hi there,

Here are some possible causes:

  1. Members from two different replsets in the same connection string

  2. Two replsets with the same name

Hope this helps!