RUBY-133 maximum insert size

This commit is contained in:
Kyle Banker 2010-06-15 10:24:31 -04:00
parent 62d917edd2
commit 4712a68468
2 changed files with 13 additions and 0 deletions

View File

@ -670,6 +670,8 @@ module Mongo
message = BSON::ByteBuffer.new([0, 0, 0, 0])
BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{collection_name}")
documents.each { |doc| message.put_array(BSON::BSON_CODER.serialize(doc, check_keys, true).to_a) }
raise InvalidOperation, "Exceded maximum insert size of 16,000,000 bytes" if message.size > 16_000_000
if safe
@connection.send_message_with_safe_check(Mongo::Constants::OP_INSERT, message, @db.name,
"#{@db.name}['#{collection_name}'].insert(#{documents.inspect})", safe)

View File

@ -115,6 +115,17 @@ class TestCollection < Test::Unit::TestCase
end
end
def test_maximum_insert_size
docs = []
16.times do
docs << {'foo' => 'a' * 1_000_000}
end
assert_raise InvalidOperation do
@@test.insert(docs)
end
end
if @@version >= "1.5.1"
def test_safe_mode_with_advanced_safe_with_invalid_options
assert_raise_error ArgumentError, "Unknown key(s): wtime" do