{"record":{"id":"76da8dc1259b0720","repo":"mongodb/mongoid","slug":"document-not-found-for-class-klass-with-attribu","errorCode":null,"errorMessage":"Document not found for class %{klass} with attributes %{attributes}.","messagePattern":"Document not found for class %(.+?) with attributes %(.+?)\\.","errorType":"exception","errorClass":"Mongoid::Errors::DocumentNotFound","httpStatus":404,"severity":"error","filePath":"lib/mongoid/association/nested/many.rb","lineNumber":210,"sourceCode":"          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\n\n          parent.children_may_have_changed!\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":192,"sourceCodeEnd":219,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/nested/many.rb#L192-L219","documentation":"update_nested_relation failed to find the referenced document when reparenting is not allowed (or the HABTM lookup missed), so the id given in nested attributes does not correspond to an existing persisted document.","triggerScenarios":"Thrown at lib/mongoid/association/nested/many.rb:210 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the ids in nested attributes belong to existing documents of the association class","Enable Mongoid.allow_reparenting_via_nested_attributes if pushing existing documents is intended","Rescue Mongoid::Errors::DocumentNotFound to handle stale ids gracefully"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","contentChangedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}