@@ -509,7 +509,7 @@ def find_and_modify(opts={})
509509      @db . command ( cmd ) [ 'value' ] 
510510    end 
511511
512-     # Perform a map/ reduce operation on the current collection. 
512+     # Perform a map- reduce operation on the current collection. 
513513    # 
514514    # @param [String, BSON::Code] map a map function, written in JavaScript. 
515515    # @param [String, BSON::Code] reduce a reduce function, written in JavaScript. 
@@ -529,11 +529,13 @@ def find_and_modify(opts={})
529529    # @option opts [Boolean ] :verbose (false) if true, provides statistics on job execution time. 
530530    # @option opts [Boolean] :raw (false) if true, return the raw result object from the map_reduce command, and not 
531531    #   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 . 
534534    # 
535535    # @return [Collection, Hash] a Mongo::Collection object or a Hash with the map-reduce command's results. 
536536    # 
537+     # @raise ArgumentError if you specify {:out => {:inline => true}} but don't specify :raw => true. 
538+     # 
537539    # @see http://www.mongodb.org/display/DOCS/MapReduce Offical MongoDB map/reduce documentation. 
538540    # 
539541    # @core mapreduce map_reduce-instance_method 
@@ -553,10 +555,13 @@ def map_reduce(map, reduce, opts={})
553555        raise  Mongo ::OperationFailure ,  "map-reduce failed: #{ result [ 'errmsg' ] }  " 
554556      end 
555557
556-       if  raw  || ! result [ "result" ] 
558+       if  raw 
557559        result 
558-       else 
560+       elsif   result [ "result" ] 
559561        @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." 
560565      end 
561566    end 
562567    alias  :mapreduce  :map_reduce 
0 commit comments