mongodb/mongoid · error · Mongoid::Errors::NoMapReduceOutput
No output location was specified for the map/reduce…
Error message
No output location was specified for the map/reduce operation.
What it means
validate_out! runs before executing or iterating a map/reduce: the command requires an output location (out) and none was set via MapReduce#out. MongoDB rejects map/reduce without output, so Mongoid raises first.
Solutions
- Chain .out(inline: 1) or an output collection on the map_reduce criteria
- Avoid map/reduce without a declared output location
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at lib/mongoid/contextual/map_reduce.rb:224 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/4ce126c2660bb4c7.
Report an issue: GitHub.
Appendix: source
Thrown at lib/mongoid/contextual/map_reduce.rb:224
class: #{criteria.klass}
map: #{command[:map]}
reduce: #{command[:reduce]}
finalize: #{command[:finalize]}
out: #{command[:out].inspect}>
)
end
# Returns the selector of the command spec.
#
# @return [ Hash ] The selector.
def command
@map_reduce.send(:map_reduce_spec)[:selector]
end
private
def validate_out!
raise Errors::NoMapReduceOutput.new({}) unless @map_reduce.out
end
def _session
criteria.send(:_session)
end
end
end
end
View on GitHub (pinned to 0da0e23d71)