mongodb/mongoid · error · Mongoid::Errors::TooManyNestedAttributeRecords
Accepting nested attributes for %{association} is limited to
Error message
Accepting nested attributes for %{association} is limited to %{limit} documents. What it means
Error "Accepting nested attributes for %{association} is limited to %{limit} documents." thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/association/nested/many.rb:30
# passed to the macro.
#
# This attempts to perform 3 operations, either one of an update of
# the existing association, a replacement of the association with a new
# document, or a removal of the association.
#
# It raises an argument error if the attributes are not a Hash or an
# Array of key/value pairs.
#
# @example Build the nested attrs.
# many.build(person)
#
# @param [ Document ] parent The parent document of the association.
# @param [ Hash ] options The options.
#
# @return [ Array ] The attributes.
def build(parent, options = {})
@existing = parent.send(association.name)
raise Errors::TooManyNestedAttributeRecords.new(existing, options[:limit]) if over_limit?(attributes)
attributes.each do |attrs|
if attrs.is_a?(::Hash)
process_attributes(parent, attrs.with_indifferent_access)
elsif attrs.is_a?(Array) && attrs.length > 1 && attrs[1].respond_to?(:with_indifferent_access)
process_attributes(parent, attrs[1].with_indifferent_access)
elsif attrs.is_a?(Array) && attrs.length.even?
process_attributes(parent, Hash[*attrs].with_indifferent_access)
else
raise ArgumentError,
"Attributes for nested association '#{association.name}' must be a Hash or an Array of key/value pairs."
end
end
end
# Create the new builder for nested attributes on one-to-many
# associations.
#View on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/association/nested/many.rb:30 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23).
Data as JSON: /api/errors/103869e5d85d299f.
Report an issue: GitHub.