Class: Mongo::URI::SRVProtocol

Inherits:
Mongo::URI show all
Defined in:
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

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 Loggable

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

Constructor Details

This class inherits a constructor from Mongo::URI

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



46
47
48
49
50
# File 'lib/mongo/uri/srv_protocol.rb', line 46

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