@@ -509,7 +509,7 @@ def find_and_modify(opts={})
509
509
@db . command ( cmd ) [ 'value' ]
510
510
end
511
511
512
- # Perform a map/ reduce operation on the current collection.
512
+ # Perform a map- reduce operation on the current collection.
513
513
#
514
514
# @param [String, BSON::Code] map a map function, written in JavaScript.
515
515
# @param [String, BSON::Code] reduce a reduce function, written in JavaScript.
@@ -529,11 +529,13 @@ def find_and_modify(opts={})
529
529
# @option opts [Boolean ] :verbose (false) if true, provides statistics on job execution time.
530
530
# @option opts [Boolean] :raw (false) if true, return the raw result object from the map_reduce command, and not
531
531
# the instantiated collection that's returned by default. Note if a collection name isn't returned in the
532
- # map-reduce output (as, for example, when using :out => {:inline => 1}), then this option will be
533
- # forced to true .
532
+ # map-reduce output (as, for example, when using :out => {:inline => 1}), then you must specify this option
533
+ # or an ArgumentError will be raised .
534
534
#
535
535
# @return [Collection, Hash] a Mongo::Collection object or a Hash with the map-reduce command's results.
536
536
#
537
+ # @raise ArgumentError if you specify {:out => {:inline => true}} but don't specify :raw => true.
538
+ #
537
539
# @see http://www.mongodb.org/display/DOCS/MapReduce Offical MongoDB map/reduce documentation.
538
540
#
539
541
# @core mapreduce map_reduce-instance_method
@@ -553,10 +555,13 @@ def map_reduce(map, reduce, opts={})
553
555
raise Mongo ::OperationFailure , "map-reduce failed: #{ result [ 'errmsg' ] } "
554
556
end
555
557
556
- if raw || ! result [ "result" ]
558
+ if raw
557
559
result
558
- else
560
+ elsif result [ "result" ]
559
561
@db [ result [ "result" ] ]
562
+ else
563
+ raise ArgumentError , "Could not instantiate collection from result. If you specified " +
564
+ "{:out => {:inline => true}}, then you must also specify :raw => true to get the results."
560
565
end
561
566
end
562
567
alias :mapreduce :map_reduce
0 commit comments