minhhungit / mongodb-cluster-docker-compose

docker-compose for mongodb cluster sharded with replication

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

show an example of connecting to cluster with mongodb driver

ORESoftware opened this issue · comments

So I have these containers running now:

CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                                            NAMES
233900e71ca8        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 3 minutes        0.0.0.0:27121->27017/tcp                         rydell-mongo-config-03
9bfd351f9cdf        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27120->27017/tcp                         rydell-mongo-config-02
94163eb82215        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27119->27017/tcp                         rydell-mongo-config-01
61e289602d5d        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27128->27017/tcp                         rydell-shard-03-node-a
dbc527b7ba24        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27118->27017/tcp                         rydell-router-02
cce70b2cb752        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27122->27017/tcp                         rydell-shard-01-node-a
db1a7f001bc3        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27125->27017/tcp                         rydell-shard-02-node-a
06f031e7b2f5        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27129->27017/tcp                         rydell-shard-03-node-b
3b83eefa2e30        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27123->27017/tcp                         rydell-shard-01-node-b
cabcd65b4092        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27124->27017/tcp                         rydell-shard-01-node-c
057dfb770b27        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27130->27017/tcp                         rydell-shard-03-node-c
66b2f9a266a6        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27117->27017/tcp                         rydell-router-01
977ff9982704        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27127->27017/tcp                         rydell-shard-02-node-c
9b607ded9559        mongo:4.0                                             "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27126->27017/tcp                         rydell-shard-02-node-b

how do I know which ones I should connect in a mongod:// connection string?

commented

There is a sample I wrote by C# here https://github.com/minhhungit/mongodb-cluster-docker-compose/tree/master/client

here is sample connectionstring

var client = new MongoClient($"mongodb://127.0.0.1:27117,127.0.0.1:27118/{dbName}");

commented

27117 and 27118 in this sample are routers

commented

Closing due to inactivity