elixir-mongo / mongodb_ecto

MongoDB adapter for Ecto
Apache License 2.0
370 stars 126 forks source link

Can't connect Repo to Atlas Cluster #186

Closed wizardone closed 2 years ago

wizardone commented 2 years ago

Hi All, I know there's been a couple of issues around connectivity with Atlas, but this one seems to be slightly different. I have the following config available:

config :my_app, MyApp.Repo,
  url: "mongo_atlas_url",
  ssl: true,
  ssl_opts: [ciphers: [{:rsa, :aes_256_gcm, :aead, :sha384}], versions: [:"tlsv1.2"]]

and a repo file, which doesn't do anything:

defmodule MyApp.Repo do
  use Ecto.Repo, otp_app: :My_app, adapter: Mongo.Ecto

  def init(_, config) do
    IO.inspect(config)
    {:ok, config}
  end
end

(inspecting was done to ensure I actually pass the correct ssl configuration) And on boot of my application I get a failed to connect: ** (Mongo.Error) tcp connect: connection refused - :econnrefused Why is this issue under Repo and not MongoDB? Well, I can hook into my running elixir app with bin/my_app remote and successfully establish a connection like so:

{:ok, conn} = Mongo.start_link(url: "mongo_atlas_url", ssl: true, ssl_opts: [ciphers: [{:rsa, :aes_256_gcm, :aead, :sha384}], versions: [:"tlsv1.2"]])
{:ok, #PID<0.8015.0>}

So the instance does not have any connectivity issues. Am I missing something completely obvious here? I've spent quite some time trying to debug the issue, but no luck so far. Hopefully I can get some help, thank you all.

mongodb_ecto, "0.2.1" mongodb, "0.4.9" elixir 1.10.4

wizardone commented 2 years ago

Hopefully this will help someone else out there: the problem with these versions was that the runtime config was not recognized. After some back and forth I managed to determine that I was trying to connect to my local db url, because the information in releases.exs was not respected on the server. Since then I've upgraded to the latest beta versions of both mongo and mongo_ecto and the problem was solved 👍