elixir-mongo / mongodb

MongoDB driver for Elixir
Apache License 2.0
568 stars 157 forks source link

DNS issue when connecting to mongodb on DigitalOcean with a mongodb+srv url string #380

Closed hdecolle closed 1 year ago

hdecolle commented 1 year ago

Hi I have the setup described in the issue/379.

More details:

I have a mongodb connection string in the mongdb+srv format and I have trouble connection to the database on Digital Ocean.

Should the url: as described here or the mongo_url option as described here be used.

At the moment I use the url: option and locally it works for example when I use: mongodb://mongodb:27017/db_name it also works with ecto://mongodb:27017/db_name

NOTE: Locally everything is running in docker and mongodb is the name of the mongodb container.

When I use the mongodb+srv version I get the following error:

Mongo.Protocol  ... failed to connect: ** (Mongo Error) DATABASE_HOST tcp connect: non-existing domain - :nxdomain

The connection string is correct because a different scala container can connect successfully to the database.

Is the mongodb+srv string supported? If not what would be a workaround.

hdecolle commented 1 year ago

I can also spot the following error in the log:

%Mongo.Error{message: "Topology selection timeout", code: 89, host: nil, type: :network}
hdecolle commented 1 year ago

Hm on DigtialOcean I have the MongoDB 6.0.6 Community edition and in docker MongoDB 4.4.22 Community edition.

Could that be the problem?

hdecolle commented 1 year ago

A quick update:

When I did use the Mongo without pulling Ecto in, in a small demo, the error with the "non-existing-domain" disappeared. But I got a new one where there was an authentication problem.

I also did a small demo with the mongodb-driver and there where no issues, but MongoDB 6.0 is also listed as supported there.

I will switch to that for now and will close the issue. Maybe I will look again at a later date. Using ecto would be nice.