Method: Mongo::Client#get_session

Defined in:
lib/mongo/client.rb

#get_session(options = {}) ⇒ Session | nil

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 a session to use for operations if possible.

If :session option is set, validates that session and returns it. Otherwise, if deployment supports sessions, creates a new session and returns it. When a new session is created, the session will be implicit (lifecycle is managed by the driver) if the :implicit option is given, otherwise the session will be explicit (lifecycle managed by the application). If deployment does not support session, returns nil.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :implicit (true | false)

    When no session is passed in, whether to create an implicit session.

  • :session (Session)

    The session to validate and return.

Returns:

  • (Session | nil)

    Session object or nil if sessions are not supported by the deployment.

Since:

  • 2.0.0



1118
1119
1120
1121
1122
# File 'lib/mongo/client.rb', line 1118

def get_session(options = {})
  get_session!(options)
rescue Error::SessionsNotSupported
  nil
end