Skip to content

Upgrade Mongoid 8.1.3 -> 9.1 #881

Description

@suttondemlong

Why

mongoid 8.1.3 declares activemodel >= 5.1, < 7.2. It is a hard resolution blocker for Rails 7.2 — bundle update rails cannot work around it.

Mongoid 9.1 declares activemodel >= 5.1, < 8.2, so it supports Rails 7.1 and 8.1. That means this can land on Rails 7.1, before the framework bump, where a failure is unambiguous. Verified: rails 7.1.6 + mongoid 9.1.0 resolves cleanly.

Why this one is on its own

Highest-risk change in the sequence. Major ODM version, and it pulls mongo 2.20 -> 2.25 and bson 4.15 -> 5.2 (a major bump). 15 models include Mongoid::Document.

Scope / things to work through

  • Set Mongoid.load_defaults 9.0 in config/initializers/mongoid.rb (currently 8.1). Consider landing the gem bump on 8.1 first and flipping defaults in a follow-up commit.
  • Verify the BSON::ObjectId monkey patch in that initializer (it aliases to_json/as_json to to_s) still behaves under bson 5. This one patch shapes every ID in every API response. Mongoid 9 also ships an ActiveJob serializer for BSON::ObjectId which may make part of it redundant.
  • Mongoid::Document.send(:include, ActiveModel::SerializerSupport) and the Mongoid::Criteria.delegate(:active_model_serializer, ...) line in the same initializer are AMS 0.9 glue — exercise the controller specs specifically.
  • Mongoid 9 defaults embedded associations to touch: true. Checked: this app has zero embeds_many/embeds_oneCheckin uses has_many with class_name: "Checkin::Treatment" etc. So the new default does not apply.
  • symmetric-encryption registers Mongoid::Fields.option :encrypted, which is the linchpin of the Postgres<->Mongo encrypted_user_id link. Checked: Mongoid 9's CSFLE uses the encrypt: option, not encrypted:, so there is no collision. Still worth a smoke test round-tripping a Checkin through encrypted_user_id back to a Postgres User.
  • Confirm MongoDB 4.4.9 (docker-compose and the supercharge/mongodb-github-action pin in CI) is still supported by mongo driver 2.25. If not, bumping the server image should land first.

Sibling gems to re-verify: cancancan-mongoid, kaminari-mongoid, database_cleaner-mongoid, mongoid-rspec.

Acceptance criteria

  • Full suite green (33 model + 18 controller specs are the real check)
  • encrypted_user_id round-trip verified
  • API response ID formatting unchanged

Blocked by

#880 (upgrade prep). Blocks #883.


Part of the Ruby + Rails upgrade sequence. Ruby 3.2 reached end of life on 2026-04-01 and the backend is on Rails 7.1; the goal is Ruby 3.4.10 and Rails 8.1, in steps that each keep CI green and are independently deployable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions