Merge pull request #79 from johnewart/fix_db_out_option
RUBY-389: Fix db output option on Collection#map_reduce
This commit is contained in:
commit
ebd31d0cd0
@ -628,7 +628,12 @@ module Mongo
|
|||||||
if raw
|
if raw
|
||||||
result
|
result
|
||||||
elsif result["result"]
|
elsif result["result"]
|
||||||
|
if result['result'].is_a? BSON::OrderedHash and result['result'].has_key? 'db' and result['result'].has_key? 'collection'
|
||||||
|
otherdb = @db.connection[result['result']['db']]
|
||||||
|
otherdb[result['result']['collection']]
|
||||||
|
else
|
||||||
@db[result["result"]]
|
@db[result["result"]]
|
||||||
|
end
|
||||||
else
|
else
|
||||||
raise ArgumentError, "Could not instantiate collection from result. If you specified " +
|
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."
|
"{:out => {:inline => true}}, then you must also specify :raw => true to get the results."
|
||||||
|
@ -559,6 +559,19 @@ class TestCollection < Test::Unit::TestCase
|
|||||||
@@test.map_reduce(m, r, :raw => true, :out => {:inline => 1})
|
@@test.map_reduce(m, r, :raw => true, :out => {:inline => 1})
|
||||||
assert res["results"]
|
assert res["results"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_map_reduce_with_collection_output_to_other_db
|
||||||
|
@@test << {:user_id => 1}
|
||||||
|
@@test << {:user_id => 2}
|
||||||
|
|
||||||
|
m = Code.new("function() { emit(this.user_id, 1); }")
|
||||||
|
r = Code.new("function(k,vals) { return 1; }")
|
||||||
|
res = @@test.map_reduce(m, r, :out => {:replace => 'foo', :db => 'somedb'})
|
||||||
|
assert res["result"]
|
||||||
|
assert res["counts"]
|
||||||
|
assert res["timeMillis"]
|
||||||
|
assert res.find.to_a.any? {|doc| doc["_id"] == 2 && doc["value"] == 1}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user