123456789_123456789_123456789_123456789_123456789_

Module: Mongo::ServerSelector

Overview

Functionality for getting an object able to select a server, given a preference.

Since:

  • 2.0.0

Constant Summary

Instance Method Summary

Instance Method Details

#get(preference = {})

Create a server selector object.

Examples:

Get a server selector object for selecting a secondary with

specific tag sets.
Mongo::ServerSelector.get(:mode => :secondary, :tag_sets => [{'dc' => 'nyc'}])

Parameters:

  • preference (Hash) (defaults to: {})

    The server preference.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector.rb', line 75

def get(preference = {})
  return preference if PREFERENCES.values.include?(preference.class)
  Mongo::Lint.validate_underscore_read_preference(preference)
  PREFERENCES.fetch((preference[:mode] || :primary).to_sym).new(preference)
end

#primary

This method is for internal use only.

Returns the primary server selector.

A call to this method is equivalent to ‘get(mode: :primary)`, except the resulting server selector object is cached and not recreated each time.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector.rb', line 87

def primary
  @primary ||= get(mode: :primary)
end