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

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


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.


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?

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