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
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
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
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #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.