Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch underlying driver to mongodb_driver for MongoDB 6.0+ support #190

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

brennana
Copy link

@brennana brennana commented Jan 9, 2024

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.

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

…one/3

Basing staleness on the modified_count is incorrect, since updates that match a document but leave it as-is is a successful no-op. The action should only be considered stale if the update query did not match any documents.
@scottmessinger
Copy link
Collaborator

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!

@zookzook
Copy link

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

@scottmessinger
Copy link
Collaborator

Thank you @zookzook!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants