mongodb/mongoid · error · Mongoid::Errors::UnregisteredClass

The class is not registered with the resolver .

Error message

The class %{klass} is not registered with the resolver %{resolver}.

What it means

Raised by Mongoid::ModelResolver#keys_for when the class of the given record was never registered with this resolver via register_model (or register). The resolver maps model classes to alias keys and raises Mongoid::Errors::UnregisteredClass when asked for keys of an unknown class.

Solutions

  1. Register the model class with the resolver (e.g. via include/resolver registration API) before querying keys
  2. Verify the correct resolver is being used for this model
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/mongoid/model_resolver.rb:136 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/ca4730bb13cbe7af. Report an issue: GitHub.

Appendix: source

Thrown at lib/mongoid/model_resolver.rb:136

      # Returns the list of all keys for the given record's class, in priority order (with highest
      # priority keys first).
      #
      # @param [ Mongoid::Document] record the record instance for which to query the registered keys.
      #
      # @raise Mongoid::Errors::UnregisteredClass if the record's class has not been registered with this resolver.
      #
      # @return [ Array<String> ] the list of keys that have been registered for the given class.
      def keys_for(record)
        @model_to_keys.fetch(record.class) do |klass|
          # figure out which resolver this is
          resolver = if self == Mongoid::ModelResolver.instance
                       :default
                     else
                       Mongoid::ModelResolver.resolvers.keys.detect { |k| Mongoid::ModelResolver.resolvers[k] == self }
                     end
          resolver ||= self # if it hasn't been registered, we'll show it the best we can
          raise Mongoid::Errors::UnregisteredClass.new(klass, resolver)
        end
      end

      # Returns the document class that has been registered by the given key.
      #
      # @param [ String ] key the key by which to query the corresponding class.
      #
      # @raise Mongoid::Errors::UnrecognizedModelAlias if the given key has not
      #   been registered with this resolver.
      #
      # @return [ Class ] the document class that has been registered with the given key.
      def model_for(key)
        @key_to_model.fetch(key) do
          raise Mongoid::Errors::UnrecognizedModelAlias, key
        end
      end
    end
  end

View on GitHub (pinned to 0da0e23d71)