{"record":{"id":"b2cf71aa10fbdc98","repo":"mongodb/mongoid","slug":"must-specify-a-class-or-a-document-instance","errorCode":null,"errorMessage":"must specify a class or a document instance","messagePattern":"must specify a class or a document instance","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/mongoid/persistence_context.rb","lineNumber":62,"sourceCode":"      @object = object\n      set_options!(opts)\n    end\n\n    # Returns a new persistence context that is consistent with the given\n    # child document, inheriting most appropriate settings.\n    #\n    # @param [ Mongoid::Document | Class ] document the child document\n    #\n    # @return [ PersistenceContext ] the new persistence context\n    #\n    # @api private\n    def for_child(document)\n      if document.is_a?(Class)\n        return self if document == (@object.is_a?(Class) ? @object : @object.class)\n      elsif document.is_a?(Mongoid::Document)\n        return self if document.class == (@object.is_a?(Class) ? @object : @object.class)\n      else\n        raise ArgumentError, 'must specify a class or a document instance'\n      end\n\n      PersistenceContext.new(document, options.merge(document.storage_options))\n    end\n\n    # Get the collection for this persistence context.\n    #\n    # @example Get the collection for this persistence context.\n    #   context.collection\n    #\n    # @param [ Object ] parent The parent object whose collection name is used\n    #   instead of this persistence context's collection name.\n    #\n    # @return [ Mongo::Collection ] The collection for this persistence\n    #   context.\n    def collection(parent = nil)\n      if parent\n        parent.collection.with(client_options.except(:database, 'database'))","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/persistence_context.rb#L44-L80","documentation":"Error \"must specify a class or a document instance\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/persistence_context.rb:62 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"}