Map-reduce doc update for v1.8
This commit is contained in:
parent
fa0a933780
commit
4f3937d6a4
|
@ -509,7 +509,7 @@ module Mongo
|
||||||
@db.command(cmd)['value']
|
@db.command(cmd)['value']
|
||||||
end
|
end
|
||||||
|
|
||||||
# Perform a map/reduce operation on the current collection.
|
# Perform a map-reduce operation on the current collection.
|
||||||
#
|
#
|
||||||
# @param [String, BSON::Code] map a map function, written in JavaScript.
|
# @param [String, BSON::Code] map a map function, written in JavaScript.
|
||||||
# @param [String, BSON::Code] reduce a reduce function, written in JavaScript.
|
# @param [String, BSON::Code] reduce a reduce function, written in JavaScript.
|
||||||
|
@ -529,11 +529,13 @@ module Mongo
|
||||||
# @option opts [Boolean ] :verbose (false) if true, provides statistics on job execution time.
|
# @option opts [Boolean ] :verbose (false) if true, provides statistics on job execution time.
|
||||||
# @option opts [Boolean] :raw (false) if true, return the raw result object from the map_reduce command, and not
|
# @option opts [Boolean] :raw (false) if true, return the raw result object from the map_reduce command, and not
|
||||||
# the instantiated collection that's returned by default. Note if a collection name isn't returned in the
|
# the instantiated collection that's returned by default. Note if a collection name isn't returned in the
|
||||||
# map-reduce output (as, for example, when using :out => {:inline => 1}), then this option will be
|
# map-reduce output (as, for example, when using :out => {:inline => 1}), then you must specify this option
|
||||||
# forced to true.
|
# or an ArgumentError will be raised.
|
||||||
#
|
#
|
||||||
# @return [Collection, Hash] a Mongo::Collection object or a Hash with the map-reduce command's results.
|
# @return [Collection, Hash] a Mongo::Collection object or a Hash with the map-reduce command's results.
|
||||||
#
|
#
|
||||||
|
# @raise ArgumentError if you specify {:out => {:inline => true}} but don't specify :raw => true.
|
||||||
|
#
|
||||||
# @see http://www.mongodb.org/display/DOCS/MapReduce Offical MongoDB map/reduce documentation.
|
# @see http://www.mongodb.org/display/DOCS/MapReduce Offical MongoDB map/reduce documentation.
|
||||||
#
|
#
|
||||||
# @core mapreduce map_reduce-instance_method
|
# @core mapreduce map_reduce-instance_method
|
||||||
|
@ -553,10 +555,13 @@ module Mongo
|
||||||
raise Mongo::OperationFailure, "map-reduce failed: #{result['errmsg']}"
|
raise Mongo::OperationFailure, "map-reduce failed: #{result['errmsg']}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if raw || !result["result"]
|
if raw
|
||||||
result
|
result
|
||||||
else
|
elsif result["result"]
|
||||||
@db[result["result"]]
|
@db[result["result"]]
|
||||||
|
else
|
||||||
|
raise ArgumentError, "Could not instantiate collection from result. If you specified " +
|
||||||
|
"{:out => {:inline => true}}, then you must also specify :raw => true to get the results."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias :mapreduce :map_reduce
|
alias :mapreduce :map_reduce
|
||||||
|
|
|
@ -485,7 +485,11 @@ class TestCollection < Test::Unit::TestCase
|
||||||
res = @@test.map_reduce(m, r, :out => {:reduce => output_collection})
|
res = @@test.map_reduce(m, r, :out => {:reduce => output_collection})
|
||||||
assert res.find.to_a.any? {|doc| doc["_id"] == 3 && doc["value"]["count"] == 2}
|
assert res.find.to_a.any? {|doc| doc["_id"] == 3 && doc["value"]["count"] == 2}
|
||||||
|
|
||||||
res = @@test.map_reduce(m, r, :out => {:inline => 1})
|
assert_raise ArgumentError do
|
||||||
|
@@test.map_reduce(m, r, :out => {:inline => 1})
|
||||||
|
end
|
||||||
|
|
||||||
|
@@test.map_reduce(m, r, :raw => true, :out => {:inline => 1})
|
||||||
assert res["results"]
|
assert res["results"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue