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

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

Error message

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

What it means

Error "The class %{klass} is not registered with the resolver %{resolver}." thrown in mongodb/mongoid.

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)

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.