Cannot connect to Mongodb replicaset

I Use rancher to create an cluster with Amazon EKS.

Deployed a nodejs app in ‘default’ namespace.

Installed MongoDB replicaset from the rancher app catalog with default settings.

  • Service/Deployment name is mongodb-replicaset
  • namespace is also mongodb-replicaset

When I use
mongodb://mongodb-replicaset:27017/tradeit_system?replicaSet=rs as connection string.

I get the error.

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

Then I read in kubernetes documentation that to access a service in a different namespace you need to also specify the namespace along with the service name.

So I did this

mongodb://mongodb-replicaset.mongodb-replicaset:27017/tradeit_system?replicaSet=rss

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

Got same error with this as well.

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

Hello, I’m trying to deploy MongoDB replica set on Rancher 2.0 using catalog as well. I don’t know how to connect to my replica set, did you solved your problem?

Hi,

This connection string worked for me:

mongodb://[user]:[password]@[service].[namespace].svc.cluster.local:27017/[db]?replicaSet=rs0&authSource=admin