mongodb/mongoid · error
#{through_names.join(', ')} are :through associations and do
Error message
#{through_names.join(', ')} are :through associations and do not support $lookup-based eager loading. All inclusions for this query will be preloaded using separate queries. What it means
Error "#{through_names.join(', ')} are :through associations and do not support $lookup-based eager loading. All inclusions for this query will be preloaded using separate queries." thrown in mongodb/mongoid.
Source
Thrown at lib/mongoid/association/eager_loadable.rb:60
"#{offender.name} (client: #{offender.klass.client_name}, database: #{offender.klass.database_name})"
end
Mongoid.logger.warn(
'eager_load cannot use $lookup aggregation because the following associations ' \
"reside in a different cluster or database than #{klass} " \
"(client: #{klass.client_name}, database: #{klass.database_name}): " \
"#{offender_descriptions.join(', ')}. Falling back to #includes behavior."
)
return eager_load(docs_for_lookup_fallback)
end
through_inclusions = criteria.inclusions.select do |association|
association.is_a?(Association::Referenced::HasOneThrough) ||
association.is_a?(Association::Referenced::HasManyThrough)
end
if through_inclusions.any?
through_names = through_inclusions.map { |association| ":#{association.name}" }
Mongoid.logger.warn(
"#{through_names.join(', ')} are :through associations and do not support " \
'$lookup-based eager loading. All inclusions for this query will be preloaded ' \
'using separate queries.'
)
return eager_load(docs_for_lookup_fallback)
end
documents = preload_for_lookup(criteria)
# A polymorphic belongs_to cannot be expressed as a $lookup: its target
# collection varies per document. It is resolved after the roots are
# materialized, each inclusion by its own preloader.
criteria.inclusions.select(&:polymorphic?).each do |association|
EagerLoad::PolymorphicPreloader.new(association, klass).preload_into(documents)
end
documents
end
# Load the associations for the given documents. This will be doneView on GitHub (pinned to 0da0e23d71)
When it happens
Trigger: Thrown at lib/mongoid/association/eager_loadable.rb:60 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/ef5c0f475359e41f.
Report an issue: GitHub.