# Cannot connect to Mongodb replicaset

**URL:** https://forums.suse.com/t/cannot-connect-to-mongodb-replicaset/11653
**Category:** General
**Created:** [August 31, 2018, 10:01am UTC](https://forums.suse.com/t/cannot-connect-to-mongodb-replicaset/11653 "2018-08-31T10:01:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Praveen901](https://avatars.discourse-cdn.com/v4/letter/p/ccd318/32.png) [@Praveen901](https://forums.suse.com/u/Praveen901)
#### Post date: [August 31, 2018, 10:01am UTC](https://forums.suse.com/t/cannot-connect-to-mongodb-replicaset/11653/1 "2018-08-31T10:01:41Z")

</div>

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](https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services) 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`

---

<div class="post-metadata">

### Author: ![rnmkr](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@rnmkr](https://forums.suse.com/u/rnmkr)
#### Post date: [September 28, 2018, 5:32pm UTC](https://forums.suse.com/t/cannot-connect-to-mongodb-replicaset/11653/2 "2018-09-28T17:32:46Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![slimee](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/slimee/32/4574_2.png) [@slimee](https://forums.suse.com/u/slimee)
#### Post date: [October 24, 2018, 3:21pm UTC](https://forums.suse.com/t/cannot-connect-to-mongodb-replicaset/11653/3 "2018-10-24T15:21:21Z")

</div>

Hi,

This connection string worked for me:

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