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

Merged
merged 11 commits into from
Oct 15, 2024

Conversation

brennana
Copy link
Contributor

@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. 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 added 4 commits June 27, 2023 15:51
…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!

@mweidner037
Copy link
Collaborator

Hey @brennana, I'll be testing out the PR this week! Could you allow changes to your branch? I'll push fixes for the CI and make any revisions if needed.

@brennana
Copy link
Contributor Author

Hi @mweidner037, I have added you for write access to our fork of the repo. Let me know if you need anything else.

For whatever reason, there does not seem to be an option to allow collaborators access to our fork through this PR, as per the GitHub documentation you linked. Perhaps it's because the fork is owned by my organization, not sure.

@mweidner037
Copy link
Collaborator

Thanks! I've tested this out in our app and found no issues.

For apps that call the Mongo driver directly, some other migration changes to note:

  • Mongo.ReadPreference.defaults -> Mongo.ReadPreference.merge_defaults
  • Mongo.command: Pass the command as a keyword list instead of a struct (as done in this PR).
  • When passing a hint to Mongo.find_one (etc.?), if the index does not exist, an error is now returned. This is Mongo's intended behavior, but apparently it was not happening with the old driver (perhaps the hint was not passed properly?).

I'll merge this and start on a migration guide for the next release.

@mweidner037 mweidner037 merged commit dfd21c5 into elixir-mongo:master Oct 15, 2024
19 checks passed
@mweidner037 mweidner037 mentioned this pull request Oct 21, 2024
@KoushikDasika
Copy link

Thank you for your work, everybody. I'm going through this upgrade because of Atlas's force upgrade EOM. this is well appreciated. The cut over on the ecto queries was super smooth. I find myself only needing to update the direct Mongo aggregation queries.

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.

5 participants