{"record":{"id":"e90461ff7fe7f254","repo":"mongodb/mongoid","slug":"document-s-not-found-for-class-klass-with-id-s","errorCode":null,"errorMessage":"Document(s) not found for class %{klass} with id(s) %{missing}.","messagePattern":"Document\\(s\\) not found for class %(.+?) with id\\(s\\) %(.+?)\\.","errorType":"exception","errorClass":"Mongoid::Errors::DocumentNotFound","httpStatus":404,"severity":"error","filePath":"lib/mongoid/association/nested/many.rb","lineNumber":193,"sourceCode":"        #   builder.update_nested_relation(parent, id, attrs)\n        #\n        # @param [ Document ] parent The parent document.\n        # @param [ String | BSON::ObjectId ] id of the related document.\n        # @param [ Hash ] attrs The single document attributes to process.\n        def update_nested_relation(parent, id, attrs)\n          first = existing.first\n          converted = first ? convert_id(first.class, id) : id\n\n          if existing.where(_id: converted).exists?\n            # document exists in association\n            doc = existing.find(converted)\n            if destroyable?(attrs)\n              destroy(parent, existing, doc)\n            else\n              update_document(doc, attrs)\n            end\n          elsif association.embedded?\n            raise Errors::DocumentNotFound.new(association.klass, id)\n          elsif association.is_a?(Association::Referenced::HasAndBelongsToMany) || Mongoid.allow_reparenting_via_nested_attributes?\n            unless destroyable?(attrs)\n              Mongoid::Warnings.warn_reparenting_via_nested_attributes if Mongoid.allow_reparenting_via_nested_attributes?\n\n              # push existing document to association\n              doc = association.klass.unscoped.find(converted)\n              # find returns nil instead of raising when\n              # Mongoid.raise_not_found_error is false; a missing document\n              # must still be an error here, consistent with the other\n              # not-found branches.\n              raise Errors::DocumentNotFound.new(association.klass, id) if doc.nil?\n\n              update_document(doc, attrs)\n              existing.push(doc)\n            end\n          else\n            raise Errors::DocumentNotFound.new(association.klass, { _id: id, association.foreign_key => parent.id })\n          end","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/nested/many.rb#L175-L211","documentation":"Error \"Document(s) not found for class %{klass} with id(s) %{missing}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/nested/many.rb:193 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"}