How to specify the connection string when connecting to a mongodb replicaset in a different namespace?


#1

I have a cluster created with Amazon EKS.

mongodb-replicaset is running as a catalog app.
namespace : mongodb-replicaset
service name : mongodb-replicaset

I have a node app running in the same cluster in the default namespace that I want to connect to the mongodb replicaset.

The connection string I specified was

mongodb://mongodb-replicaset.mongodb-replicaset.svc.cluster.local:27017/tradeit_system?replicaSet=rs

I specified the namespace also because the node app and the database are in different namespaces.

This is the error I get.

MongoError: no primary found in replicaset or invalid replica set name

If I doesn’t specify the namespace.

mongodb://mongodb-replicaset:27017/tradeit_system?replicaSet=rs

I get this error.

MongoNetworkError: failed to connect to server [mongodb-replicaset-1:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND mongodb-replicaset mongodb-replicaset:27017]

What is the correct way to specify this?


#2

I have the same error.
did you manage to solve?