When Mongoid::Config.raise_not_found_error = false is set globally and a nested-attributes hash references a :_id for a child that doesn't exist on a has_and_belongs_to_many relation (or any relation that flows through Many#update_nested_relation's reparenting branch), the find lookup returns nil rather than raising Errors::DocumentNotFound. The nil is then passed straight to Many#update_document, which calls nil.update_attributes(attrs) and raises NoMethodError. See attached bug.rb. We have worked around this by doing a hack:
module Mongoid # Mongoid 9.0.x's Many#update_document raises NoMethodError when an entry # references a non-existent _id and `Mongoid::Config.raise_not_found_error` # is false (the lookup returns nil rather than raising). Guard against it. module Association module Nested class Many def update_document(doc, attrs) return if doc.nil? # Added this delete_id(attrs) if association.embedded? doc.assign_attributes(attrs) else doc.update(attrs) end end end end end end