I'm struggling to set up MongoDB in my Phoneix project

I am trying to configure a mongodb database to my phoneix project (with contains already a postgres config), but I dodn’t get it right :

I use the library : GitHub - elixir-mongo/mongodb: MongoDB driver for Elixir

But there is no steps to add the config variables to my config.exs / runtime.exs

Can you please tell me the steps to configure it just like the Postgres / Ecto way ?

This doesn’t help? It’s in the README though the details I am not familiar with since I haven’t used Mongo in ages.

That uses MongoDB Ecto, I just need the simple mongo driver set up to connect to my Mongo Atlas cluser

I tried this :

But I always get this error :

Hi.

I’m using this mongodb library with success with and without phoenix: mongodb_driver | Hex

It supports recent mongodb versions, is actively maintained and is working with mogodb atlas also. Even with using x509 authentication.

Cheers
Frank

Thanks @suchasurge, did you succed to find a document by ObjectId, I tried this but I got nil :

iex(6)> Mongo.find_one(:mongo, "books", %{"_id" => "605201b6099f1c001f5f1e4d"}) 
nil

yes, I had no problems with queries so far.

I do it like that:

Mongo.find_one(:mongo, "books", %{_id: "id"})

But I also use custom IDs and not the auto generated object ids from mongodb, so maybe this makes a difference.

Cheers
Frank

try

Mongo.find_one(:mongo, "books", %{"_id" => BSON.ObjectId.decode!("605201b6099f1c001f5f1e4d")}) 

The _id is usually an ObjectId and not a binary. Keep in mind that the driver does not mapping automatically binaries into the native data representation like ObjectID or UUID.