gke-mongodb-demo icon indicating copy to clipboard operation
gke-mongodb-demo copied to clipboard

Missing sample connection URL in README

Open djensen47 opened this issue 6 years ago • 4 comments

It might be nice to include what the connection URL would be inside the cluster for this setup.

It seems like it would be:

mongodb://mongod-0.mongodb-service,mongod-1.mongodb-service,mongod-2.mongodb-service:27017/dbname

djensen47 avatar Jan 13 '18 22:01 djensen47

Did you ever manage to connect? I can't seem to figure it out, this is the url I'm trying:

`mongodb://${MONGO_CONFIG.auth.user}:${MONGO_CONFIG.auth.password}@mongod-0.mongodb-service,mongod-1.mongodb-service,mongod-2.mongodb-service:27017/${DB_NAME}`

flauc avatar Jan 28 '18 12:01 flauc

The url I posted works for me.

djensen47 avatar Jan 29 '18 06:01 djensen47

@djensen47 thanks 👍

flauc avatar Jan 29 '18 07:01 flauc

I would rather leave the primary/secondary handling for the service itself, so I am using this: mongodb://user:[email protected]/?replicaSet=MainRepSet&authSource=admin (I also have 3 replicas)

That gives you this (I am debugging it with a Java app), note the other replica hostnames handled automatically:

org.mongodb.driver.cluster: Monitor thread successfully connected to server with description ServerDescription{address=mongodb-0.mongodb.default.svc.cluster.local:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, ..., setName='MainRepSet', canonicalAddress=mongodb-0.mongodb.default.svc.cluster.local:27017, hosts=[mongodb-2.mongodb.default.svc.cluster.local:27017, mongodb-0.mongodb.default.svc.cluster.local:27017, mongodb-1.mongodb.default.svc.cluster.local:27017], ..., primary='mongodb-0.mongodb.default.svc.cluster.local:27017', ...}
org.mongodb.driver.cluster: Setting max election id to 7fffffff0000000000000001 from replica set primary mongodb-0.mongodb.default.svc.cluster.local:27017
org.mongodb.driver.cluster: Setting max set version to 1 from replica set primary mongodb-0.mongodb.default.svc.cluster.local:27017
org.mongodb.driver.cluster: Discovered replica set primary mongodb-0.mongodb.default.svc.cluster.local:27017

caiobegotti avatar Jul 31 '18 19:07 caiobegotti