dersar00
Hello!
Git Repository here.
I have a problem with saving data to database. I use mongodb_ecto adapter, when I try save it through iex console I can do it:
iex(1)> Friends.PersonController.save()
START SAVING
SAVED
09:58:17.706 [debug] QUERY OK db=0.4ms
INSERT coll="people" document=[age: 11, _id: #BSON.ObjectId<5b027c190d1a8f0f042d5600>] []
:ok
or
iex(1)> person = %Friends.Person{}
%Friends.Person{
__meta__: #Ecto.Schema.Metadata<:built, "people">,
age: nil,
first_name: nil,
id: nil,
last_name: nil
}
iex(2)> Friends.Repo.insert(person)
10:50:43.451 [debug] QUERY OK db=0.4ms
INSERT coll="people" document=[_id: #BSON.ObjectId<5b0288630d1a8f06ef2e3699>] []
{:ok,
%Friends.Person{
__meta__: #Ecto.Schema.Metadata<:loaded, "people">,
age: nil,
first_name: nil,
id: "5b0288630d1a8f06ef2e3699",
last_name: nil
}}
But if uncomment Friends.PersonController.save and try to call it when program is work, I got error:
⇒ mix
Compiling 1 file (.ex)
START SAVING
== Compilation error in file lib/friends.ex ==
** (ArgumentError) argument error
(stdlib) :ets.lookup_element(Mongo.IdServer, :machineprocid, 2)
lib/mongo/id_server.ex:50: Mongo.IdServer.new/0
lib/ecto/repo/schema.ex:651: Ecto.Repo.Schema.autogenerate_id/4
lib/ecto/repo/schema.ex:199: anonymous fn/13 in Ecto.Repo.Schema.do_insert/4
lib/friends/person_controller.ex:11: Friends.PersonController.save/0
lib/friends.ex:4: (module)
What’s the solution for it? How I can do it?
I have an assumption that when I run the program, I just do not start Mongo?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nicd
It looks to me like you are calling
Friends.PersonController.save()at compile time in your code. And at compile time, your DB application is not started naturally.Can you show the code of
lib/friends.exandlib/friends/person_controller.ex?dersar00
Oh, sorry, I forgot to attach my repository.
Git Repository here.
Look to
masterNobbZ
As @Nicd said, you are calling at compiletime. Then all the drivers and ecto aren’t running.
Nicd
https://github.com/dersar00/friends/blob/master/lib/friends.ex
When this module is compiled, it will call the save function at compile time. That’s probably not what you want to do.
dersar00
So how I can call it after compiling?
It’s a test project what I can publish. In my real dev project I have a program what’s listening a
rabbitmqqueue, when I get message I have a task to save it, so how I can at first compile program and after use without any problems?Nicd
Call the function in the code that does the handling of the RabbitMQ message. I don’t know how your program works to tell you the exact place.
dersar00
I call it, but I get the same error.
Nicd
Where? We need more details.
dersar00
For example my main file looks like here.
Nicd
Have you started the Ecto application and your repos when running that? How are you running it? I can’t see it in your git repo. It seems you may have a misunderstanding of how Elixir applications are started.