From e4570c133de0444478dcf576c017847211a3768b Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Fri, 6 Jan 2012 14:53:23 -0500 Subject: [PATCH] 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)