I’m working on a project that uses :mongodb_driver (GitHub - zookzook/elixir-mongodb-driver: MongoDB driver for Elixir). I use Ecto changesets but not full ecto queries. I’d like to be able to use libraries that use Ecto so I am looking into adding full Ecto via :mongodb_ecto. :mongodb_driver README says it has supported Ecto since v1.4.0.
I picked this driver some time ago as the repo seemed more alive. This driver also provides watch_collection which allows my elixir service to respond to changes in mongo.
:mongdb_ecto seems typically to use :mongodb, a different driver.
:mongdb_ecto expects the struct Mongo.Query to have the key :extra. :mongodb has this key in that struct, :mongodb_driver does not.
I’m using current versions, and have tried combinations of older versions but have not found a combination where this works.
I’m considering forking :mongodb_ecto to handle this, on the presumption that whatever :extra is doing I can work around it or bypass it as I don’t need it. If I find something elegant I can offer PR. I’m also asking :mongodb_driver maintainers if I can contribute, in which case I’ll figure out what work :extra is doing and submit a PR that supports it.
Maybe someboy else has figured this out and I can do something similar to what they did and not have to do the above.
Alternatively, maybe somebody has a different idea altogether. I’m open. I’m even willing to discuss at length “why aren’t you just using Postgres” which I expect from this joyus community. I might even find a path to that less costly than anything else, and projects like GitHub - mathieuprog/polymorphic_embed: Polymorphic embeds in Ecto make this more tenable. But for now presume that I’d just like to learn how :mongodb_driver works with :mongodb_ecto, like I believe that it says it does.
FWIW, there’s already a PR that claims to switch mongodb_ecto to use mongodb_driver from January:
However, I agree with your assessment that the extra key will cause problems - particularly in Mongo.Ecto.Connection.format_query where every head expects a Mongo.Query to have that key:
I tried using :mongodb_ecto for some time but reverted to using the zookzook driver directly. The driver can model collections, and I can create something like an ecto repo that starts up with the application.
I can still use Ecto.Changeset where it makes sense. I found this setup much more stable.
I see. In my case I was dealing with multiple repos, SQL-based and MongoDB. Trying to use Ecto with mongo had so many caveats that I felt it was only getting in the way. I’d rather write MongoDB queries directly and have access to aggregation operations.
For this particular case, have you considered customizing the templates?