From 28796ac7deb9ffb303cb6792b3bbd20138742d9b Mon Sep 17 00:00:00 2001 From: John Ewart Date: Wed, 14 Dec 2011 17:49:08 -0800 Subject: [PATCH 1/6] Support :db key for :out in map_reduce References RUBY-389 --- lib/mongo/collection.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index b5b98a5..7cd0b36 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -624,7 +624,12 @@ module Mongo if raw result elsif result["result"] - @db[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"]] + end 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." From 6c0b3723e9bec25dd32b65ae6c69b6f5611b1f47 Mon Sep 17 00:00:00 2001 From: John Ewart Date: Thu, 15 Dec 2011 08:06:01 -0800 Subject: [PATCH 2/6] =?UTF-8?q?Adding=20test=20for=20the=20:out=20=3D>=20{?= =?UTF-8?q?:db=20=E2=80=A6}=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Forgot to add the test in the last commit. --- test/collection_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/collection_test.rb b/test/collection_test.rb index df61389..d3f46a9 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -546,6 +546,19 @@ class TestCollection < Test::Unit::TestCase @@test.map_reduce(m, r, :raw => true, :out => {:inline => 1}) assert res["results"] 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 From 217da825a694a447524cccaed1038245c2b1837b Mon Sep 17 00:00:00 2001 From: Ryunosuke SATO Date: Tue, 27 Dec 2011 19:55:10 +0900 Subject: [PATCH 3/6] remove unused error class 'ConfigurationError' --- lib/mongo/exceptions.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/mongo/exceptions.rb b/lib/mongo/exceptions.rb index 2403cf9..3e39fdc 100644 --- a/lib/mongo/exceptions.rb +++ b/lib/mongo/exceptions.rb @@ -37,9 +37,6 @@ module Mongo end end - # Raised when configuration options cause connections, queries, etc., to fail. - class ConfigurationError < MongoRubyError; end - # Raised on fatal errors to GridFS. class GridError < MongoRubyError; end From af441efb7c32f044eef761d80c852b9d2e5b5a82 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 28 Dec 2011 01:15:11 +0100 Subject: [PATCH 4/6] Remove noop assignment --- lib/mongo/gridfs/grid.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongo/gridfs/grid.rb b/lib/mongo/gridfs/grid.rb index 0f55e0b..d8aa018 100644 --- a/lib/mongo/gridfs/grid.rb +++ b/lib/mongo/gridfs/grid.rb @@ -70,7 +70,7 @@ module Mongo opts = opts.dup filename = opts[:filename] opts.merge!(default_grid_io_opts) - file = GridIO.new(@files, @chunks, filename, 'w', opts=opts) + file = GridIO.new(@files, @chunks, filename, 'w', opts) file.write(data) file.close file.files_id From ebfab91f53e938043239f91d82fcc25bb622ca74 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 6 Jan 2012 00:37:56 -0800 Subject: [PATCH 5/6] Fixed scoping issue that causes connection to hang w/ :connect_timeout option --- lib/mongo/connection.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index 57c3947..318c917 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -604,6 +604,8 @@ module Mongo def check_is_master(node) begin host, port = *node + socket = nil + config = nil if @connect_timeout Mongo::TimeoutHandler.timeout(@connect_timeout, OperationTimeout) do From e4570c133de0444478dcf576c017847211a3768b Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Fri, 6 Jan 2012 14:53:23 -0500 Subject: [PATCH 6/6] RUBY-356 clarify docs on continue_on_error --- lib/mongo/collection.rb | 4 ++++ test/collection_test.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index b5b98a5..d014ad4 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -333,6 +333,10 @@ module Mongo # @option opts [Boolean] :continue_on_error (+false+) If true, then # continue a bulk insert even if one of the documents inserted # triggers a database assertion (as in a duplicate insert, for instance). + # If not using safe mode, the list of ids returned will + # include the object ids of all documents attempted on insert, even + # if some are rejected on error. When safe mode is + # enabled, any error will raise an OperationFailure exception. # MongoDB v2.0+. # # @core insert insert-instance_method diff --git a/test/collection_test.rb b/test/collection_test.rb index df61389..9b04456 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -151,6 +151,19 @@ class TestCollection < Test::Unit::TestCase end end + def test_bulk_insert + @@test.remove + docs = [] + docs << {:foo => 1} + docs << {:foo => 2} + docs << {:foo => 3} + response = @@test.insert(docs) + assert_equal 3, response.length + assert response.all? {|id| id.is_a?(BSON::ObjectId)} + assert_equal 3, @@test.count + @@test.remove + end + def test_bulk_insert_with_continue_on_error if @@version >= "2.0" @@test.create_index([["foo", 1]], :unique => true)