javamongodbquarkusreplicasetmongodb-replica-set

Connecting to MongoDB replica set results in "Expecting replica set member, but found a STANDALONE"


I am trying to connect to my local MongoDB replica set (configured via Docker Compose) via an application running on Quarkus, however I am getting the following error as soon as I try to access the database via the application:

2022-01-24 14:51:03,170 ERROR [org.mon.dri.cluster] (cluster- ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo1:27017) Expecting replica set member, but found a STANDALONE.  Removing mongo1:27017 from client view of cluster.
2022-01-24 14:51:03,177 ERROR [org.mon.dri.cluster] (cluster-ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo3:27017) Expecting replica set member, but found a STANDALONE.  Removing mongo3:27017 from client view of cluster.
2022-01-24 14:51:03,182 ERROR [org.mon.dri.cluster] (cluster-ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo2:27017) Expecting replica set member, but found a STANDALONE.  Removing mongo2:27017 from client view of cluster.
2022-01-24 14:51:08,179 ERROR [nl.rab.kno.int.LoggingInterceptor] (executor-thread-0) LoggingInterceptor.MethodCallEvent(className=nl.rabobank.knowledge.service.PreferencesService, methodName=getLanguagesForUser, result=EXCEPTION, exception=com.mongodb.MongoTimeoutException: Timed out after 5000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@31e1baef. Client view of cluster state is {type=REPLICA_SET, servers=[])

For some reason it seems to identify my nodes as standalone, instead of replica set members, afterwhich they are getting removed from the client view of the cluster. I am wondering what goes wrong here?

This is the connection string that I am using in my Quarkus application:

quarkus:
    mongodb:
        connection-string: mongodb://mongo1:27021,mongo2:27022,mongo3:27023/database?replicaSet=dbrs

I simply followed this guide for setting up a replica set in MongoDB with Docker Compose: https://blog.tericcabrel.com/mongodb-replica-set-docker-compose/.

These are the dependencies used by my Quarkus application (version 2.6.2):

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-mongodb-client</artifactId>
</dependency>
<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-mongodb-panache</artifactId>
</dependency>

Solution

  • It looks like I found the problem. I managed to get rid of that specific error after removing Mongo on my local machine, resulting in only having Mongo as part of my containerised nodes.

    However, I am running into another issue now for which I created this post: Connecting to containerised MongoDB replica set with Docker results in "Canonical address ... does not match server address.".