Phoenix - Connection to mongodb

Heya, so it’s been a while since the last time I touched phoenix and now I’m not finding my way when attempting to connect to a mongodb DB I have running in AWS. I’m defining the worker as:

{Mongo, [
          database: "my_db_name",
          hostname: "mongo://my-remote-db:27017",
          username: "my_username",
          password: "my_password",
          ssl: true,

and getting in return

** (Mix) Could not start application my_app: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: Mongo
    ** (EXIT) an exception was raised:
        ** (FunctionClauseError) no function clause matching in anonymous fn/1 in Keyword.take/2
            (elixir 1.13.0) lib/keyword.ex:1131: anonymous fn([database: "my_db_name", hostname: "mongo://my-remote-db:27017", username: "my_username", password: "my_password", ssl: true]) in Keyword.take/2
            (elixir 1.13.0) lib/keyword.ex:1131: Keyword."-take/2-lists^filter/1-0-"/2
            (mongodb 0.5.1) lib/mongo/topology.ex:20: Mongo.Topology.start_link/2
            (stdlib 3.15) supervisor.erl:414: :supervisor.do_start_child_i/3
            (stdlib 3.15) supervisor.erl:400: :supervisor.do_start_child/2
            (stdlib 3.15) supervisor.erl:384: anonymous fn/3 in :supervisor.start_children/2
            (stdlib 3.15) supervisor.erl:1234: :supervisor.children_map/4
            (stdlib 3.15) supervisor.erl:350: :supervisor.init_children/2
            (stdlib 3.15) gen_server.erl:423: :gen_server.init_it/2
            (stdlib 3.15) gen_server.erl:390: :gen_server.init_it/6
            (stdlib 3.15) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

I have the dep installed. What am I missing?

Is this the library that you are using: mongo | Hex?

If so it is nearly 7 years old, I’d aim to use something newer. Are you looking to connect to MongoDB directly or with Ecto?

Right, that’s the one.
I’d aim for none of them but being that the DB already exists then I could go with Ecto since it’s already known to me.
From what I found - everything is old and the support is limited.
What would you suggest?

I think this one GitHub - zookzook/elixir-mongodb-driver: MongoDB driver for Elixir is actively developed …

I could go with this one, but:

1 defmodule MyApp.Repo do
2  use Mongo.Repo,
3    otp_app: :my_app,
4    topology: :mongo
5 end

Resolves into:

(CompileError) lib/deci_admin_panel/repo.ex:2: module Mongo.Repo is not loaded and could not be found

Mongo.Repo support is part of very recent changes. Do you run this version?

For a fresh start, try this (run a local MongoDB)

  • add {:mongodb_driver, “~> 0.9.0-rc.0”} to dependencies
  • run mix deps.get
  • add {Mongo, [name: :mongo, url: “mongodb://localhost:27017/your-db”]} to your application.ex file
  • Mongo.find(:mongo, “your-collection”, %{}) |> Enum.to_list()

You can change the url to your running AWS instance as well. But sometimes your need to add some more config parameters (ssl stuff).