-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.10.0
-
Component/s: None
-
None
When connected to a legacy (pre-2.6) version of MongoDB, the Bulk API will raise OperationFailure if the server response includes a jnote or wnote field. This was done to mimic the error a 2.6 standalone returns if a write concern with w > 1 is used or a mongo cluster returns if :j => true is used with journaling disabled.
Unfortunately, the server will also return wnote if the write concern was not satisfied because no write operations were performed (e.g. an update or remove operation that didn't match any documents).
2.1.1 :005 > bulk = coll.initialize_ordered_bulk_op => #<Mongo::BulkWriteCollectionView:0x70193705170520 @collection=#<Mongo::Collection:0x70193705198880>, @options={:ordered=>true}, @ops=[], @op_args={:q=>nil}> 2.1.1 :006 > bulk.find({"something" => "that doesn't exist"}).remove => #<Mongo::BulkWriteCollectionView:0x70193705170520 @collection=#<Mongo::Collection:0x70193705198880>, @options={:ordered=>true}, @ops=[[:delete, {:q=>{"something"=>"that doesn't exist"}, :limit=>0}]], @op_args={:q=>{"something"=>"that doesn't exist"}}> 2.1.1 :007 > bulk.execute({:w => 1}) Mongo::BulkWriteError: batch item errors occurred from /Users/emilystolfo/.rvm/gems/ruby-2.1.1/gems/mongo-1.10.0/lib/mongo/bulk_write_collection_view.rb:230:in `execute' from (irb):7 from /Users/emilystolfo/.rvm/rubies/ruby-2.1.1/bin/irb:11:in `<main>' 2.1.1 :014 > client['admin'].command('ismaster' => 1) => {"setName"=>"ruby-driver-test", "ismaster"=>true, "secondary"=>false, "hosts"=>["localhost:3000", "localhost:3002", "localhost:3001"], "primary"=>"localhost:3000", "tags"=>{"node"=>"0"}, "me"=>"localhost:3000", "maxBsonObjectSize"=>16777216, "maxMessageSizeBytes"=>48000000, "localTime"=>2014-04-24 21:25:11 UTC, "ok"=>1.0} 2.1.1 :015 > client.server_version => #<Mongo::ServerVersion:0x007f8c343c46d8 @version="2.4.9">
The impact of this bug should be limited by a few factors:
- This error is only raised by the Bulk API, not collection#insert/update/remove
- The execute method has to be called with a custom write concern with w > 1. No error is raised when using the default write acknowledgement or :w => 1.
- The bug only manifests with server versions before 2.6. The bulk API is only really useful from a performance perspective when connected to MongoDB 2.6 or newer.