mongodb-erlang
mongodb-erlang copied to clipboard
Cannot connect to Mongo Atlas
I have setup a mongo cluster on mongo cloud (ATLAS) .
application:ensure_all_started (mongodb).
Seed = { rs, <<"xxxxx-shard-0">>, [ "xxxxx-shard-00-00-hbcsf.mongodb.net:27017", "xxxxx-shard-00-01-hbcsf.mongodb.net:27017", "xxxxx-shard-00-02-hbcsf.mongodb.net:27017"] }.
TopologyOptions=[{name, <<"xx_pool">>},{register, xx_pool},{pool_size, 1},{ssl, true},{max_overflow, 10}].
WorkerOptions=[{database, <<"test">>}].
{ok, Topology} = mongoc:connect(Seed, TopologyOptions, WorkerOptions).
I get below error on connection.
=ERROR REPORT==== 23-Aug-2018::17:59:36 ===
** Generic server <0.107.0> terminating
** Last message in was {tcp_closed,#Port<0.999>}
** When Server state == {state,#Port<0.999>,
#{14 => #Fun<mc_worker_logic.1.13189865>},
<<21,3,1,0,2,2,10>>,
{conn_state,unsafe,master,<<"admin">>,<<"admin">>},
undefined,#Fun<mc_worker.0.34453686>,gen_tcp}
** Reason for termination ==
** tcp_closed
Are you able to connect to it using some other driver/tool?
Yes i am able to connect using Java/C/C++ driver as well mongo shell. mongo "mongodb+srv://xxxx-hbcsf.mongodb.net/test" --username xxxx --password xxxxx
MongoDB shell version v4.0.1
connecting to: mongodb+srv://xxxx-hbcsf.mongodb.net/test
2018-08-24T11:19:42.803+0530 I NETWORK [js] Starting new replica set monitor for xxxxx-shard-0/xxxx-shard-00-00-hbcsf.mongodb.net.:27017,xxxxx-shard-00-01-hbcsf.mongodb.net.:27017,xxxx-shard-00-02-hbcsf.mongodb.net.:27017
2018-08-24T11:19:43.810+0530 I NETWORK [js] Successfully connected to xxxxx-shard-00-00-hbcsf.mongodb.net.:27017 (1 connections now open to xxxxx-shard-00-00-hbcsf.mongodb.net.:27017 with a 5 second timeout)
2018-08-24T11:19:43.963+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to xxxxx-shard-00-01-hbcsf.mongodb.net.:27017 (1 connections now open to xxxxx-shard-00-01-hbcsf.mongodb.net.:27017 with a 5 second timeout)
2018-08-24T11:19:44.081+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor] changing hosts to xxxx-shard-0/xxxx-shard-00-00-hbcsf.mongodb.net:27017,xxxx-shard-00-01-hbcsf.mongodb.net:27017,xxxxx-shard-00-02-hbcsf.mongodb.net:27017 from xxxxx-shard-0/xxxxx-shard-00-00-hbcsf.mongodb.net.:27017,xxxxx-shard-00-01-hbcsf.mongodb.net.:27017,xxxxx-shard-00-02-hbcsf.mongodb.net.:27017
2018-08-24T11:19:45.133+0530 I NETWORK [js] Successfully connected to xxxxx-shard-00-01-hbcsf.mongodb.net:27017 (1 connections now open to xxxxx-shard-00-01-hbcsf.mongodb.net:27017 with a 5 second timeout)
2018-08-24T11:19:45.798+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to xxxxxx-shard-00-02-hbcsf.mongodb.net:27017 (1 connections now open to xxxxxxx-shard-00-02-hbcsf.mongodb.net:27017 with a 5 second timeout)
2018-08-24T11:19:46.461+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to xxxxx-shard-00-00-hbcsf.mongodb.net:27017 (1 connections now open to xxxxx-shard-00-00-hbcsf.mongodb.net:27017 with a 5 second timeout)
sMongoDB server version: 3.6.6
WARNING: shell and server versions do not match
^R
MongoDB Enterprise xxx-shard-0:PRIMARY> show dbs
admin 0.000GB
test 0.000GB
MongoDB Enterprise xxx-shard-0:PRIMARY>
Also if i connect using mc_worker_api i can connect to master shard individually
application:ensure_all_started (mongodb).
{ok, Connection} = mc_worker_api:connect ([{database, <<"test">>},{login, <<"xxxxx">>},{password,<<"xxxxxx">>},{host,"xxxx-shard-00-01-hbcsf.mongodb.net"},{ssl,true}]).
I got you. mongoc part of driver is a little bit buggy. I will try to check it out this weekend.
thanks a bunch @comtihon
Hi, Can you please check the latest master? I've made some unification between mc_worker_api and mongoc connect.
@comtihon I checked this it still does not work.
Seed = { rs, <<"xxxxx-shard-0">>, [ "xxxxx-shard-00-00-hbcsf.mongodb.net:27017", "xxxxx-shard-00-01-hbcsf.mongodb.net:27017", "xxxxx-shard-00-02-hbcsf.mongodb.net:27017"] }.
TopologyOptions=[{name, <<"xx_pool">>},{register, xx_pool},{pool_size, 1},{ssl, true},{max_overflow, 10}].
WorkerOptions=[{database, <<"test">>}].
later on connected with
{ok, Topology} = mongoc:connect(Seed, TopologyOptions, WorkerOptions).
mongo_api:connect(sharded, [ "xxxx-shard-00-00-hbcsf.mongodb.net:27017", "xxxx-shard-00-01-hbcsf.mongodb.net:27017", "xxx-shard-00-02-hbcsf.mongodb.net:27017"], TopologyOptions, WorkerOptions)
You can try to create a test account and db on mongo atlas - https://cloud.mongodb.com/user#/atlas/login
This PR may have solved the issue of connecting to MongoDB Atlas (or any other SRV-enabled instance).
https://github.com/comtihon/mongodb-erlang/pull/237