dersar00

dersar00

Hello!
Like a mongodb driver for elixir I using Mongo.Ecto.

When I try to save something using using command insert:

of = %Friends.Person{age: 44}
Friends.Repo.insert(of)

I got error:

** (exit) exited in: GenServer.call(Friends.Repo.Pool, :topology, 5000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (elixir) lib/gen_server.ex:824: GenServer.call/3
    (mongodb) lib/mongo.ex:750: Mongo.select_servers/4
    (mongodb) lib/mongo.ex:727: Mongo.select_server/3
    (mongodb) lib/mongo.ex:501: Mongo.insert_one/4
    (mongodb_ecto) lib/mongo_ecto/connection.ex:120: Mongo.Ecto.Connection.insert/3
    (mongodb_ecto) lib/mongo_ecto.ex:630: Mongo.Ecto.insert/6
    (ecto) lib/ecto/repo/schema.ex:469: Ecto.Repo.Schema.apply/4
    (ecto) lib/ecto/repo/schema.ex:205: anonymous fn/13 in Ecto.Repo.Schema.do_insert/4

I did everything as in a guide: Getting Started — Ecto v3.14.0

Showing Posts 20 to 11

dersar00

dersar00 OP

Thanks a lot @idi527, after completing your advice, everything started workingю

idi527

idi527

What version of ecto are you using? It might be outdated.

Try replacing

  def start(_type, _args) do
    # List all child processes to be supervised
    children = [
      Friends.Repo
      # {Friends.Worker, arg},
    ]

with

def start(_type, _args) do
  import Supervisor.Spec

  # List all child processes to be supervised
  children = [
    supervisor(Friends.Repo, [])
    # {Friends.Worker, arg},
  ]

in https://github.com/dersar00/friends/blob/master/lib/friends/application.ex#L11

dersar00

dersar00 OP

I got error:

Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

Compiling 4 files (.ex)
Generated friends app
10:20:39.246 [error] Supervisor 'Elixir.Logger.Supervisor' had child 'Elixir.Logger.ErrorHandler' started with 'Elixir.Logger.Watcher':start_link({error_logger,'Elixir.Logger.ErrorHandler',{true,false,500}}) at <0.228.0> exit with reason normal in context child_terminated
10:20:39.299 [info] Application lager started on node nonode@nohost
10:20:39.304 [info] Application xmerl started on node nonode@nohost
10:20:39.307 [info] Application jsx started on node nonode@nohost
10:20:39.317 [info] Application ranch started on node nonode@nohost
10:20:39.320 [info] Application ranch_proxy_protocol started on node nonode@nohost
10:20:39.322 [info] Application recon started on node nonode@nohost
10:20:39.322 [info] Application rabbit_common started on node nonode@nohost
10:20:39.329 [info] Application amqp_client started on node nonode@nohost
10:20:39.330 [info] Application amqp started on node nonode@nohost
10:20:39.343 [info] Application decimal started on node nonode@nohost
10:20:39.345 [info] Application poolboy started on node nonode@nohost
10:20:39.350 [info] Application ecto started on node nonode@nohost
10:20:39.355 [info] Application connection started on node nonode@nohost
10:20:39.379 [info] Application db_connection started on node nonode@nohost
10:20:39.414 [info] Application mongodb started on node nonode@nohost
10:20:39.414 [info] Application mongodb_ecto started on node nonode@nohost
10:20:39.442 [error] CRASH REPORT Process <0.303.0> with 0 neighbours exited with reason: #{'__exception__' => true,'__struct__' => 'Elixir.ArgumentError',message => <<"The module Friends.Repo was given as a child to a supervisor\nbut it does not implement child_spec/1.\n\nIf you own the given module, please define a child_spec/1 function\nthat receives an argument and returns a child specification as a map.\nFor example:\n\n    def child_spec(opts) do\n      %{\n        id: __MODULE__,\n        start: {__MODULE__, :start_link, [opts]},\n        type: :worker,\n        restart: :permanent,\n  ...">>} in 'Elixir.Supervisor':init_child/1 line 635 in application_master:init/4 line 134

10:20:39.471 [info]  Application friends exited: exited in: Friends.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (ArgumentError) The module Friends.Repo was given as a child to a supervisor
but it does not implement child_spec/1.

If you own the given module, please define a child_spec/1 function
that receives an argument and returns a child specification as a map.
For example:

    def child_spec(opts) do
      %{
        id: __MODULE__,
        start: {__MODULE__, :start_link, [opts]},
        type: :worker,
        restart: :permanent,
        shutdown: 500
      }
    end

Note that "use Agent", "use GenServer" and so on automatically define
this function for you.

However, if you don't own the given module and it doesn't implement
child_spec/1, instead of passing the module name directly as a supervisor
child, you will have to pass a child specification as a map:

    %{
      id: Friends.Repo,
      start: {Friends.Repo, :start_link, [arg1, arg2]}
    }

See the Supervisor documentation for more information.

            (elixir) lib/supervisor.ex:635: Supervisor.init_child/1
            (elixir) lib/enum.ex:1294: Enum."-map/2-lists^map/1-0-"/2
            (elixir) lib/supervisor.ex:621: Supervisor.init/2
            (elixir) lib/supervisor.ex:573: Supervisor.start_link/2
            (kernel) application_master.erl:273: :application_master.start_it_old/4
10:20:39.471 [info] Application friends exited with reason: #{'__exception__' => true,'__struct__' => 'Elixir.ArgumentError',message => <<"The module Friends.Repo was given as a child to a supervisor\nbut it does not implement child_spec/1.\n\nIf you own the given module, please define a child_spec/1 function\nthat receives an argument and returns a child specification as a map.\nFor example:\n\n    def child_spec(opts) do\n      %{\n        id: __MODULE__,\n        start: {__MODULE__, :start_link, [opts]},\n        type: :worker,\n        restart: :permanent,\n  ...">>} in 'Elixir.Supervisor':init_child/1 line 635
** (Mix) Could not start application friends: exited in: Friends.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (ArgumentError) The module Friends.Repo was given as a child to a supervisor
but it does not implement child_spec/1.

If you own the given module, please define a child_spec/1 function
that receives an argument and returns a child specification as a map.
For example:

    def child_spec(opts) do
      %{
        id: __MODULE__,
        start: {__MODULE__, :start_link, [opts]},
        type: :worker,
        restart: :permanent,
        shutdown: 500
      }
    end

Note that "use Agent", "use GenServer" and so on automatically define
this function for you.

However, if you don't own the given module and it doesn't implement
child_spec/1, instead of passing the module name directly as a supervisor
child, you will have to pass a child specification as a map:

    %{
      id: Friends.Repo,
      start: {Friends.Repo, :start_link, [arg1, arg2]}
    }

See the Supervisor documentation for more information.

            (elixir) lib/supervisor.ex:635: Supervisor.init_child/1
            (elixir) lib/enum.ex:1294: Enum."-map/2-lists^map/1-0-"/2
            (elixir) lib/supervisor.ex:621: Supervisor.init/2
            (elixir) lib/supervisor.ex:573: Supervisor.start_link/2
            (kernel) application_master.erl:273: :application_master.start_it_old/4
idi527

idi527

As @NobbZ suggested, you need to add your application to your application function in mix.exs (https://github.com/dersar00/friends/blob/master/mix.exs#L15-L20), otherwise it won’t be started.

Try replacing

  def application do
    [
      # NOTE: I think you should use either :extra_applications or :applications
      # see https://www.amberbit.com/blog/2017/9/22/elixir-applications-vs-extra_applications-guide/
      applications: [:method_missing, :logger, :mongodb_ecto, :ecto],
      extra_applications: [:logger]
    ]
  end

with

def application do
  [
    mod: {Friends.Application, []}, # points to the module with application
    extra_applications: [:logger]
  ]
end
NobbZ

NobbZ

What does your mixfiles application function look like?

Is it (close to) the following?

def application do
  [mod: {Friends.Application, []}]
end
idi527

idi527

Could you please make a small repo on github with the code to reproduce this? That would help us identify the problem on our own machines and then walk you through a (hopefully) solution.

dersar00

dersar00 OP

It is from iex, I start it through iex -S mix.
ecto v2.1.6

NobbZ

NobbZ

Is this code from within your app or are you running those commands through iex?

If its from the app, how are you starting the app? Is the code public?

If it is from iex, how do you start iex?

Ankhers

Ankhers

What about your ecto version?

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
rlipscombe
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used? I’ve got two Github accoun...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews