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

Cannot find any model with type %{model_alias}

Error message

Cannot find any model with type %{model_alias}

What it means

Error "Cannot find any model with type %{model_alias}" thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/model_resolver.rb:150

                     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
end

View on GitHub (pinned to 0da0e23d71)

When it happens

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