dersar00
Error with saving to mongo db
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: https://hexdocs.pm/ecto/getting-started.html
Most Liked
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.
NobbZ
What does your mixfiles application function look like?
Is it (close to) the following?
def application do
[mod: {Friends.Application, []}]
end
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
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







