Mongo.MongoDBConnection error tcp connect: non-existing domain - :nxdomain

Hi,

I’m on Intel Mac with MacOS 11.7.2 with a MongoDB in a docker file.

Mongo CLI connects to MongoDB with default setting and I can add and list the data.

When I do ‘curl localhost:27017’ I get the expected error message ‘It looks like you are trying to access MongoDB over HTTP on the native driver port.

In the mix.exs I have a depency: {:mongodb_driver, “~> 1.0.0”}

But when I try to connect from elixir after ‘iex -S mix run’ with
{:ok, conn} = Mongo.start_link(url: “mongodb://localhost:27017/rest_api_db”)

Then I keep on receiving the error message:
[error] Mongo.MongoDBConnection (#PID<0.421.0>) failed to connect: ** (Mongo.Error) 17f29de58a5e:27017 tcp connect: non-existing domain - :nxdomain

Changing localhost to 127.0.0.1 gives the same error.

What am I doing wrong?

Solved.

‘docker compose up’ is different as ‘docker-compose up’

With the first command I cannot connect with the second I can!