Method: Mongo::Server::ConnectionCommon#handshake_document

Defined in:
lib/mongo/server/connection_common.rb

#handshake_document(app_metadata, speculative_auth_doc: nil, load_balancer: false, server_api: nil) ⇒ BSON::Document

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.

Build a document that should be used for connection handshake.

Parameters:

  • app_metadata (Server::AppMetadata)

    Application metadata

  • speculative_auth_doc (BSON::Document) (defaults to: nil)

    The speculative authentication document, if any.

  • load_balancer (true | false) (defaults to: false)

    Whether the connection is to a load balancer.

  • server_api (Hash | nil) (defaults to: nil)

    server_api Server API version.

Returns:

  • (BSON::Document)

    Document that should be sent to a server for handshake purposes.

Since:

  • 2.0.0



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/mongo/server/connection_common.rb', line 68

def handshake_document(, speculative_auth_doc: nil, load_balancer: false, server_api: nil)
  serv_api = .server_api || server_api
  document = if serv_api
               HELLO_DOC.merge(Utils.transform_server_api(serv_api))
             else
               LEGACY_HELLO_DOC
             end
  document.merge(.validated_document).tap do |doc|
    if speculative_auth_doc
      doc.update(speculativeAuthenticate: speculative_auth_doc)
    end
    if load_balancer
      doc.update(loadBalanced: true)
    end
  end
end