mongodb/mongoid · error · NotImplementedError

Mongoid no longer supports marshalling with driver version…

Error message

Mongoid no longer supports marshalling with driver version 1.x.

What it means

Raised by Criteria#marshal_load when unmarshalling criteria data that was dumped for the MongoDB driver 1.x series. The serialized format changed between driver major versions, so restoring criteria dumped under the old driver is unsupported; the faulting input is the incompatible driver version encoded in the marshalled payload.

Solutions

  1. Re-create the criteria instead of loading stale Marshal payloads
  2. Re-marshal data with a driver 2.x based Mongoid version
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/mongoid/criteria/marshalable.rb:33 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23). Data as JSON: /api/errors/ba95002714c2806f. Report an issue: GitHub.

Appendix: source

Thrown at lib/mongoid/criteria/marshalable.rb:33

      #
      # @return [ Array<Object> ] The dumped data.
      def marshal_dump
        data = [ klass, :mongo, inclusions, documents, strategy, negating, use_lookup? ]
        data.push(scoping_options).push(dump_hash(:selector)).push(dump_hash(:options))
      end

      # Resets the criteria object after a Marshal.load
      #
      # @example Load the criteria.
      #   Marshal.load(criteria)
      #
      # @param [ Array ] data The raw data.
      def marshal_load(data)
        @scoping_options, raw_selector, raw_options = data.pop(3)
        @klass, driver, @inclusions, @documents, @strategy, @negating, @use_lookup = data

        if driver == :mongo1x
          raise NotImplementedError, 'Mongoid no longer supports marshalling with driver version 1.x.'
        end

        @selector = load_hash(Queryable::Selector, raw_selector)
        @options = load_hash(Queryable::Options, raw_options)
      end

      private

      def dump_hash(name)
        send(name).each_with_object({}) do |(key, value), raw|
          raw[key] = value
        end
      end

      def load_hash(hash_class, raw)
        hash = hash_class.new(klass.aliased_fields, klass.fields)
        hash.merge!(raw)
        hash

View on GitHub (pinned to 0da0e23d71)