spec/support/cluster_tools.rb
# Adjusts replica set configuration so that the next election is likely
# to result in the server at the specified address becoming a primary.
# Address should be a Mongo::Address object.
#
# This method requires that there is an active primary in the replica set at
# the time of the call.
#
# @param [ Mongo::Address ] address
Adjusts replica set configuration so that the next election is likely
to result in the server at the specified address becoming a primary.
Address should be a Mongo::Address object.

This method requires that there is an active primary in the replica set at
the time of the call.
Adjusts replica set configuration so that the next election is likely to result in the server at the specified address becoming a primary . Address should be a Mongo :: Address object . This method requires that there is an active primary in the replica set at the time of the call .
def encourage_primary(address)
    existing_primary = admin_client.cluster.next_primary
    cfg = get_rs_config
    found = false
    cfg['members'].each do |member|
      if member['host'] == address.to_s
        member['priority'] = 10
        found = true
      elsif member['host'] == existing_primary.address.to_s
        member['priority'] = 1
      else
        member['priority'] = 0
      end
    end
    unless found
      raise "No RS member for #{address}"
    end
    set_rs_config(cfg)
  end
def encourage_primary ( address ) existing_primary = admin_client . cluster . next_primary cfg = get_rs_config found = false cfg [ 'members' ] . each do | member | if member [ 'host' ] == address . to_s member [ 'priority' ] = 10 found = true elsif member [ 'host' ] == existing_primary . address . to_s member [ 'priority' ] = 1 else member [ 'priority' ] = 0 end end unless found raise "No RS member for #{address}" end set_rs_config ( cfg ) end
Adjusts replica set configuration so that the next election is likely
to result in the server at the specified address becoming a primary.
Adjusts replica set configuration so that the next election is likely to result in the server at the specified address becoming a primary .
address
None