Skip to content

Commit

Permalink
RUBY-356 clarify docs on continue_on_error
Browse files Browse the repository at this point in the history
  • Loading branch information
banker committed Jan 6, 2012
1 parent bc872b6 commit e4570c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mongo/collection.rb
Expand Up @@ -333,6 +333,10 @@ def save(doc, opts={})
# @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
Expand Down
13 changes: 13 additions & 0 deletions test/collection_test.rb
Expand Up @@ -151,6 +151,19 @@ def test_safe_insert
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)
Expand Down

0 comments on commit e4570c1

Please sign in to comment.