mongodb_ecto icon indicating copy to clipboard operation
mongodb_ecto copied to clipboard

Switch underlying driver to mongodb_driver for MongoDB 6.0+ support

Open brennana opened this issue 1 year ago • 3 comments

This PR switches the adapter over to https://github.com/zookzook/elixir-mongodb-driver .

~~Currently, the mix.exs/mix.lock file is pointed at our fork at https://github.com/hundio/elixir-mongodb-driver until a Hex release is made with the required adapter compatibility changes.~~ The mix.exs file now points to mongodb_driver 1.4.0, rather than our own repository.

Upgrading from one driver to the other is fairly transparent for users of the Ecto adapter (unless direct calls to the driver are made outside the adapter):

  • Some Repo module config options are no longer used and can be simply deleted: pool, pool_overflow, pool_timeout.
  • If an application makes calls to the driver directly, then some modifications are required when using the new driver:
    • The pool option is no longer accepted by Mongo database command functions
    • Any command function called from the Mongo module cannot be passed a Pool module from the Repo any longer; instead, a pool PID is expected:
alias MyApp.Repo

# Old driver call
Mongo.find(Repo.Pool, "my_coll", %{"id": id}, projection: %{"field": 1}, pool: db_pool())

# New driver call
Mongo.find(Repo.pool(), "my_coll", %{"id": id}, projection: %{"field": 1})

# repo.ex
# Provided the following function is defined in MyApp.Repo:
defmodule MyApp.Repo do
  use Ecto.Repo, otp_app: :my_app, adapter: Mongo.Ecto

  def pool() do
    Ecto.Adapter.lookup_meta(__MODULE__).pid
  end
end

brennana avatar Jan 09 '24 18:01 brennana

Thanks so much, @brennana! I'm excited to review this. In looking over the commits, it seems like there's shockingly little to change. Exciting!

scottmessinger avatar Jan 09 '24 20:01 scottmessinger

The MongoDB driver 1.4.0 contains the changes needed for this PR.

zookzook avatar Feb 10 '24 11:02 zookzook

Thank you @zookzook!

scottmessinger avatar Feb 13 '24 14:02 scottmessinger