-
Type: Task
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: 2.4.0
-
Component/s: Public API
-
Environment:Mongo DB Version 3.2.7 on Ubuntu 14.04
We're using the Ruby MongoDB driver to detect if a server is the primary node of a replica set using the following check that's ran on each node of the replica set:
client = Mongo::Client.new( [server], :connect => :direct, :connect_timeout => 3, :ssl => true, :ssl_cert => '/etc/mongocerts/mongodb.pem', :ssl_key => '/etc/mongocerts/mongodb.pem', :ssl_ca_cert => '/etc/mongocerts/cacert.pem', :ssl_verify => true, :database => 'test' ) this_server = get_address_of_this_server() # A little function which returns the address of this server, have verified it returns the correct address return true if client.cluster.next_primary.address.to_s == this_server
The problem is that no matter what node we run this on `client.cluster.next_primary.address.to_s` returns the address of the node it's being ran on, and not that of the primary node.
I've been staring at this for a long time and can't see what we're doing wrong. Am I misunderstanding the API or is this a bug?