gke-mongodb-demo
gke-mongodb-demo copied to clipboard
Missing sample connection URL in README
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
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}`
The url I posted works for me.
@djensen47 thanks 👍
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