'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 1:[1]

You have forgotten to tell your nodes that, they belong to a replica set! You have two choices, command line:

mongod --replSet "rs0" --bind_ip localhost,<hostname(s)|ip address(es)>

or inside of config -file

replication:
   replSetName: "rs0"
net:
   bindIp: localhost,<hostname(s)|ip address(es)>

Check more information from here!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JJussi