mongodb/mongoid · error · Mongoid::Errors::UnrecognizedModelAlias
Cannot find any model with type
Error message
Cannot find any model with type %{model_alias} What it means
Raised by Mongoid::ModelResolver#model_for when the given type key (model alias, typically stored in the _type field) is not registered with any resolver. No document class corresponds to that alias, so Mongoid::Errors::UnrecognizedModelAlias is raised; the faulting input is the unrecognized model_alias string.
Solutions
- Register the class under the alias via the model resolver registration API
- Correct the stored alias value in the document's discriminator field
- Ensure the model class is loaded before deserialization
Defensive patterns
Strategy: try-catch
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.
Appendix: 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)