Class: Mongo::URI::SRVProtocol

Inherits:
Mongo::URI show all
Defined in:
build/ruby-driver-master/lib/mongo/uri/srv_protocol.rb

Overview

Parser for a URI using the mongodb+srv protocol, which specifies a DNS to query for SRV records. The driver will query the DNS server for SRV records on <hostname>.<domainname>, prefixed with _mongodb._tcp The SRV records can then be used as the seedlist for a Mongo::Client. The driver also queries for a TXT record providing default connection string options. Only one TXT record is allowed, and only a subset of Mongo::Client options is allowed.

Please refer to the Initial DNS Seedlist Discovery spec for details.

github.com/mongodb/specifications/blob/master/source/initial-dns-seedlist-discovery

Examples:

Use the uri string to make a client connection.

client = Mongo::Client.new('mongodb+srv://test6.test.build.10gen.cc/')

Since:

  • 2.5.0

Constant Summary

Constants inherited from Mongo::URI

AUTH_DELIM, AUTH_MECH_MAP, AUTH_USER_PWD_DELIM, DATABASE_DELIM, HELP, HOST_DELIM, HOST_PORT_DELIM, INDIV_URI_OPTS_DELIM, INVALID_OPTS_DELIM, INVALID_OPTS_VALUE_DELIM, INVALID_SCHEME, MONGODB_SCHEME, MONGODB_SRV_SCHEME, PERCENT_CHAR, READ_MODE_MAP, REPEATABLE_OPTIONS, SCHEME, SCHEME_DELIM, UNESCAPED_DATABASE, UNESCAPED_UNIX_SOCKET, UNESCAPED_USER_PWD, UNIX_SOCKET, UNSAFE, URI_OPTS_DELIM, URI_OPTS_VALUE_DELIM

Constants included from Loggable

Loggable::PREFIX

Instance Attribute Summary collapse

Attributes inherited from Mongo::URI

#options, #servers, #uri_options

Instance Method Summary collapse

Methods inherited from Mongo::URI

#credentials, #database, get, #initialize

Methods included from Address::Validator

#validate_address_str!

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger

Constructor Details

This class inherits a constructor from Mongo::URI

Instance Attribute Details

#query_hostnameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The hostname that is specified in the URI and used to look up SRV records.

This attribute needs to be defined because SRVProtocol changes #servers to be the result of the lookup rather than the hostname specified in the URI.

Returns:

  • (String)

    The hostname used in SRV lookup.

Since:

  • 2.5.0



72
73
74
# File 'build/ruby-driver-master/lib/mongo/uri/srv_protocol.rb', line 72

def query_hostname
  @query_hostname
end

#srv_recordsObject (readonly)

Since:

  • 2.5.0



39
40
41
# File 'build/ruby-driver-master/lib/mongo/uri/srv_protocol.rb', line 39

def srv_records
  @srv_records
end

#srv_resultSrv::Result (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns SRV lookup result.

Returns:

Since:

  • 2.5.0



60
61
62
# File 'build/ruby-driver-master/lib/mongo/uri/srv_protocol.rb', line 60

def srv_result
  @srv_result
end

Instance Method Details

#client_optionsHash

Gets the options hash that needs to be passed to a Mongo::Client on instantiation, so we don't have to merge the txt record options, credentials, and database in at that point - we only have a single point here.

Examples:

Get the client options.

uri.client_options

Returns:

  • (Hash)

    The options passed to the Mongo::Client

Since:

  • 2.5.0



51
52
53
54
55
# File 'build/ruby-driver-master/lib/mongo/uri/srv_protocol.rb', line 51

def client_options
  opts = @txt_options.merge(ssl: true)
  opts = opts.merge(uri_options).merge(:database => database)
  @user ? opts.merge(credentials) : opts
end