mongodb/mongoid · error · ArgumentError
instantiated results must be typecast
Error message
instantiated results must be typecast
What it means
Error "instantiated results must be typecast" thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/criteria.rb:229
# When "raw" is not set (or if `raw_results` is false), the criteria will
# return all results as instantiated Document instances.
#
# @example Return query results as raw hashes:
# Person.where(city: 'Boston').raw
#
# @param [ true | false ] raw_results Whether the new criteria should be
# placed in "raw" mode or not.
# @param [ true | false ] typed Whether the raw results should be typecast
# before being returned. Default is true if raw_results is false, and
# false otherwise.
#
# @return [ Criteria ] the cloned criteria object.
def raw(raw_results = true, typed: nil)
# default for typed is true when raw_results is false, and false when
# raw_results is true.
typed = !raw_results if typed.nil?
raise ArgumentError, 'instantiated results must be typecast' if !typed && !raw_results
clone.tap do |criteria|
criteria._raw_results = { raw: raw_results, typed: typed }
end
end
# An internal helper for getting/setting the "raw" flag on a given criteria
# object.
#
# @return [ nil | Hash ] If set, it is a hash with two keys, :raw and :typed,
# that describe whether raw results should be returned, and whether they
# ought to be typecast.
#
# @api private
attr_accessor :_raw_results
# Predicate that answers the question: is this criteria object currently
# in raw mode? (See #raw for a description of raw mode.)View on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/criteria.rb:229 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/7fe753373c9a1ce7.
Report an issue: GitHub.