{"record":{"id":"7fe753373c9a1ce7","repo":"mongodb/mongoid","slug":"instantiated-results-must-be-typecast","errorCode":null,"errorMessage":"instantiated results must be typecast","messagePattern":"instantiated results must be typecast","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/mongoid/criteria.rb","lineNumber":229,"sourceCode":"    # When \"raw\" is not set (or if `raw_results` is false), the criteria will\n    # return all results as instantiated Document instances.\n    #\n    # @example Return query results as raw hashes:\n    #   Person.where(city: 'Boston').raw\n    #\n    # @param [ true | false ] raw_results Whether the new criteria should be\n    #   placed in \"raw\" mode or not.\n    # @param [ true | false ] typed Whether the raw results should be typecast\n    #   before being returned. Default is true if raw_results is false, and\n    #   false otherwise.\n    #\n    # @return [ Criteria ] the cloned criteria object.\n    def raw(raw_results = true, typed: nil)\n      # default for typed is true when raw_results is false, and false when\n      # raw_results is true.\n      typed = !raw_results if typed.nil?\n\n      raise ArgumentError, 'instantiated results must be typecast' if !typed && !raw_results\n\n      clone.tap do |criteria|\n        criteria._raw_results = { raw: raw_results, typed: typed }\n      end\n    end\n\n    # An internal helper for getting/setting the \"raw\" flag on a given criteria\n    # object.\n    #\n    # @return [ nil | Hash ] If set, it is a hash with two keys, :raw and :typed,\n    #   that describe whether raw results should be returned, and whether they\n    #   ought to be typecast.\n    #\n    # @api private\n    attr_accessor :_raw_results\n\n    # Predicate that answers the question: is this criteria object currently\n    # in raw mode? (See #raw for a description of raw mode.)","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/criteria.rb#L211-L247","documentation":"Error \"instantiated results must be typecast\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/criteria.rb:229 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}