-
Type: Bug
-
Resolution: Unresolved
-
Priority: Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
initialize_copy sets @database to nil which makes the client returned by dup not work. For example:
irb(main):001:0> a=Mongo::Client.new(['127.0.0.1:27100']) D, [2018-10-11T16:41:32.400373 #29747] DEBUG -- : MONGODB | EVENT: #<TopologyOpening topology=Unknown[]> D, [2018-10-11T16:41:32.400495 #29747] DEBUG -- : MONGODB | Topology type 'unknown' initializing. D, [2018-10-11T16:41:32.400741 #29747] DEBUG -- : MONGODB | EVENT: #<ServerOpening address=127.0.0.1:27100 topology=Unknown[127.0.0.1:27100]> D, [2018-10-11T16:41:32.400791 #29747] DEBUG -- : MONGODB | Server 127.0.0.1:27100 initializing. D, [2018-10-11T16:41:32.402680 #29747] DEBUG -- : MONGODB | EVENT: #<Mongo::Monitoring::Event::ServerDescriptionChanged> D, [2018-10-11T16:41:32.402780 #29747] DEBUG -- : MONGODB | Server description for 127.0.0.1:27100 changed from 'unknown' to 'unknown'. D, [2018-10-11T16:41:32.402961 #29747] DEBUG -- : MONGODB | EVENT: #<ServerOpening address=localhost:27100 topology=Unknown[127.0.0.1:27100]> D, [2018-10-11T16:41:32.403006 #29747] DEBUG -- : MONGODB | Server localhost:27100 initializing. D, [2018-10-11T16:41:32.404620 #29747] DEBUG -- : MONGODB | EVENT: #<Mongo::Monitoring::Event::ServerDescriptionChanged> D, [2018-10-11T16:41:32.404701 #29747] DEBUG -- : MONGODB | Server description for localhost:27100 changed from 'unknown' to 'primary'. D, [2018-10-11T16:41:32.404874 #29747] DEBUG -- : MONGODB | EVENT: #<ServerOpening address=localhost:27101 topology=Unknown[127.0.0.1:27100]> D, [2018-10-11T16:41:32.404918 #29747] DEBUG -- : MONGODB | Server localhost:27101 initializing. D, [2018-10-11T16:41:32.406172 #29747] DEBUG -- : MONGODB | EVENT: #<Mongo::Monitoring::Event::ServerDescriptionChanged> D, [2018-10-11T16:41:32.406244 #29747] DEBUG -- : MONGODB | Server description for localhost:27101 changed from 'unknown' to 'secondary'. D, [2018-10-11T16:41:32.406459 #29747] DEBUG -- : MONGODB | EVENT: #<ServerOpening address=localhost:27102 topology=Unknown[127.0.0.1:27100]> D, [2018-10-11T16:41:32.406503 #29747] DEBUG -- : MONGODB | Server localhost:27102 initializing. D, [2018-10-11T16:41:32.407728 #29747] DEBUG -- : MONGODB | EVENT: #<Mongo::Monitoring::Event::ServerDescriptionChanged> D, [2018-10-11T16:41:32.407797 #29747] DEBUG -- : MONGODB | Server description for localhost:27102 changed from 'unknown' to 'secondary'. D, [2018-10-11T16:41:32.407969 #29747] DEBUG -- : MONGODB | EVENT: #<TopologyChanged prev=Unknown[127.0.0.1:27100] new=ReplicaSetNoPrimary> D, [2018-10-11T16:41:32.408028 #29747] DEBUG -- : MONGODB | Topology type 'unknown' changed to type 'replicasetnoprimary'. D, [2018-10-11T16:41:32.408577 #29747] DEBUG -- : MONGODB | EVENT: #<Mongo::Monitoring::Event::ServerClosed> D, [2018-10-11T16:41:32.408633 #29747] DEBUG -- : MONGODB | Server 127.0.0.1:27100 connection closed. D, [2018-10-11T16:41:32.408818 #29747] DEBUG -- : MONGODB | EVENT: #<TopologyChanged prev=ReplicaSetNoPrimary new=ReplicaSetWithPrimary> D, [2018-10-11T16:41:32.408872 #29747] DEBUG -- : MONGODB | Topology type 'replicasetnoprimary' changed to type 'replicasetwithprimary'. => #<Mongo::Client:0x47314406949200 cluster=#<Cluster topology=ReplicaSetWithPrimary servers=[#<Server address=localhost:27100 PRIMARY replica_set=ruby-driver-rs>,#<Server address=localhost:27101 SECONDARY replica_set=ruby-driver-rs>,#<Server address=localhost:27102 SECONDARY replica_set=ruby-driver-rs>]>> irb(main):002:0> b=a.dup => #<Mongo::Client:0x47314406663380 cluster=#<Cluster topology=ReplicaSetWithPrimary servers=[#<Server address=localhost:27100 PRIMARY replica_set=ruby-driver-rs>,#<Server address=localhost:27101 SECONDARY replica_set=ruby-driver-rs>,#<Server address=localhost:27102 SECONDARY replica_set=ruby-driver-rs>]>> irb(main):003:0> b.database => nil irb(main):004:0> a.database => #<Mongo::Database:0x47314406899640 name=admin> irb(main):005:0> D, [2018-10-11T16:41:42.411746 #29747] DEBUG -- : MONGODB | EVENT: #<Mongo::Monitoring::Event::ServerDescriptionChanged> D, [2018-10-11T16:41:42.411877 #29747] DEBUG -- : MONGODB | Server description for 127.0.0.1:27100 changed from 'unknown' to 'unknown'. b['test'] Traceback (most recent call last): 3: from /home/w/.rbenv/versions/2.5.1/bin/irb:11:in `<main>' 2: from (irb):5 1: from /home/w/apps/ruby-driver/lib/mongo/client.rb:139:in `[]' NoMethodError (undefined method `[]' for nil:NilClass) irb(main):006:0> a['test'] => #<Mongo::Collection:0x47314405367640 namespace=admin.test>