-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.9.0-alpha4
-
Component/s: None
-
None
-
ALL
-
Query Optimization 2021-05-03, Query Optimization 2021-05-17, Query Optimization 2021-05-31, Query Optimization 2021-06-14, Query Optimization 2021-06-28
When I use OP_INSERT to talk to 4.9.0-alpha5 server, and I have the server configured to require API version, and I do not provide an API version in the OP_INSERT:
- standalone and replica set deployments communicate the error via getLastError, but insert the document anyway
- sharded cluster deployment communicate the error via getLastError and do not insert the document
Test code (Ruby):
require 'mongo' def test(port) client = Mongo::Client.new(["localhost:#{port}"], server_api: {version: 1}) client.use('test')['test'].delete_many p client.use('test')['test'].count client.cluster.next_primary.with_connection do |conn| insert = Mongo::Protocol::Insert.new('test', 'test', [{'name' => 'testing'}]) p conn.dispatch([insert]) query = Mongo::Protocol::Query.new('test', '$cmd', {getLastError: 1}, limit: 1) p conn.dispatch([query]) query = Mongo::Protocol::Query.new('test', 'test', { 'name' => 'testing' }) p conn.dispatch([query]) end p client.use('test')['test'].count p client.use('test')['test'].find.first end [14900, 14920, 14940].each do |port| puts puts "Testing #{port}" test(port) end
Result (14900 is standalone, 14920 is replica set, 14940 is sharded cluster):
Testing 14900 0 nil #<Mongo::Protocol::Reply:0x000056461861e2c0 @flags=[:await_capable], @cursor_id=0, @starting_from=0, @number_returned=1, @documents=[{"ok"=>0.0, "errmsg"=>"The apiVersion parameter is required, please configure your MongoClient's API version", "code"=>498870, "codeName"=>"Location498870"}]> #<Mongo::Protocol::Reply:0x000056461861c6f0 @flags=[:await_capable], @cursor_id=0, @starting_from=0, @number_returned=1, @documents=[{"_id"=>BSON::ObjectId('6053cac6baaddddc71400803'), "name"=>"testing"}], @upconverter=#<Mongo::Protocol::Reply::Upconverter:0x000056461861c1a0 @documents=[{"_id"=>BSON::ObjectId('6053cac6baaddddc71400803'), "name"=>"testing"}], @cursor_id=0, @starting_from=0>> 1 {"_id"=>BSON::ObjectId('6053cac6baaddddc71400803'), "name"=>"testing"} Testing 14920 0 nil #<Mongo::Protocol::Reply:0x00005646184a1640 @flags=[:await_capable], @cursor_id=0, @starting_from=0, @number_returned=1, @documents=[{"ok"=>0.0, "errmsg"=>"The apiVersion parameter is required, please configure your MongoClient's API version", "code"=>498870, "codeName"=>"Location498870", "$clusterTime"=>{"clusterTime"=>#<BSON::Timestamp:0x00005646184a1258 @seconds=1616104134, @increment=2>, "signature"=>{"hash"=><BSON::Binary:0x1660 type=generic data=0x0000000000000000...>, "keyId"=>0}}, "operationTime"=>#<BSON::Timestamp:0x00005646184a0fb0 @seconds=1616104134, @increment=2>}]> #<Mongo::Protocol::Reply:0x00005646184ae638 @flags=[:await_capable], @cursor_id=0, @starting_from=0, @number_returned=1, @documents=[{"_id"=>BSON::ObjectId('6053cac6bb72891ab2565f93'), "name"=>"testing"}], @upconverter=#<Mongo::Protocol::Reply::Upconverter:0x00005646184addf0 @documents=[{"_id"=>BSON::ObjectId('6053cac6bb72891ab2565f93'), "name"=>"testing"}], @cursor_id=0, @starting_from=0>> 1 {"_id"=>BSON::ObjectId('6053cac6bb72891ab2565f93'), "name"=>"testing"} Testing 14940 0 nil #<Mongo::Protocol::Reply:0x00005646183bfa88 @flags=[:await_capable], @cursor_id=0, @starting_from=0, @number_returned=1, @documents=[{"ok"=>0.0, "errmsg"=>"The apiVersion parameter is required, please configure your MongoClient's API version", "code"=>498870, "codeName"=>"Location498870", "$clusterTime"=>{"clusterTime"=>#<BSON::Timestamp:0x00005646183bf678 @seconds=1616104129, @increment=1>, "signature"=>{"hash"=><BSON::Binary:0x1780 type=generic data=0x0000000000000000...>, "keyId"=>0}}, "operationTime"=>#<BSON::Timestamp:0x00005646183bf268 @seconds=1616104129, @increment=1>}]> #<Mongo::Protocol::Reply:0x00005646183bd648 @flags=[], @cursor_id=0, @starting_from=0, @number_returned=0, @documents=[], @upconverter=#<Mongo::Protocol::Reply::Upconverter:0x00005646183bd3c8 @documents=[], @cursor_id=0, @starting_from=0>> 0 nil