D4no0

D4no0

State of mongodb drivers and integration with ecto

I currently have to deal with a mongodb database and I am quite confused about the state of the libraries when it comes to dealing with mongodb.

The one that I see being actively maintained is elixir-mongodb-driver by @zookzook , even though the actual hex package name is named mongodb_driver.

It seems that the library provides a few constructs that are ecto-alike with Mongo.Collection:

document do
    attribute :name, String.t(), default: "warning"
    attribute :color, String.t(), default: :red
  end

This is pretty nice, however it lacks the critical features of data validation provided by ecto and changesets. In the documentation it is specified that there is ecto support too: The Elixir Driver for MongoDB — mongodb-driver v1.6.3

The question, does this integration work as expected? It does seem like mongodb_ecto was updated for the latest driver version. Can it be used for production or I should just give up and use mongodb_driver only?

PS: I’ve also found library mongodb located in the same namespace as mongodb_ecto, seems like an alternative implementation of the driver?

Marked As Solved

zookzook

zookzook

It depends.

MongoDB offers numerous features that are not supported by Ecto. Some developers make the mistake of modelling MongoDB like a relational database. A certain amount of rethinking is necessary there. Basically, you do not need an Ecto layer, as you can formulate the statements directly with maps.

You can use the following:

  • plain MongoDB commands: just maps or keyword lists
  • plain MongoDB command + Mongo.Collection (structs instead of maps)
  • MongoEcto wrapper: data validation + changesets. For MongoDB specific features you have to switch back to plain MongoDB commands

The package mongodb_driver is no longer being developed. To be able to use the current MongoDB versions (6, 7, 8), I recommend the elixir-mongodb-driver :slight_smile:

Also Liked

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement