class Mongo::Session::ClientSession
- Mongo::Session::ClientSession
- Reference
- Object
Overview
A client session used to logically bind operations together.
Defined in:
cryomongo/sessions/sessions.crcryomongo/sessions/transactions.cr
Instance Method Summary
-
#abort_transaction(*, write_concern : WriteConcern? = nil)
Aborts the currently active transaction in this session.
-
#advance_cluster_time(cluster_time : ClusterTime)
This method advances the cluster_time.
-
#advance_operation_time(operation_time : BSON::Timestamp)
This method advances the operation_time.
-
#cluster_time : ClusterTime?
This property returns the most recent cluster time seen by this session.
-
#commit_transaction(*, write_concern : WriteConcern? = nil)
Commits the currently active transaction in this session.
-
#current_transaction_options : Mongo::Session::TransactionOptions
Options for the current transaction.
-
#end
Aborts any currently active transaction and ends this session.
- #is_transaction?
-
#operation_time : BSON::Timestamp?
This property returns the operation time of the most recent operation performed using this session.
-
#options : Options
The session options used when creating the session.
-
#recovery_token : BSON?
The recoveryToken field enables the driver to recover a sharded transaction's outcome on a new mongos when the original mongos is no longer available.
-
#recovery_token=(recovery_token : BSON?)
The recoveryToken field enables the driver to recover a sharded transaction's outcome on a new mongos when the original mongos is no longer available.
-
#server_description : SDAM::ServerDescription?
Server description if the session is pinned to a specific mongos.
-
#start_transaction(**options)
Starts a new transaction with the given options.
-
#transaction_state : TransactionState
The state of the transaction.
-
#transitions_from : TransactionState?
The state from where the transaction is transitioning.
-
#with_transaction(**options, &)
Same as
#start_transaction
but will commit the transaction after the block returns.
Instance Method Detail
Aborts the currently active transaction in this session.
NOTE Raises an error if this session has no transaction.
client = Mongo::Client.new
session = client.start_session
session.start_transaction
client["db"]["collection"].tap { |collection|
collection.insert_one({_id: 1}, session: session)
collection.insert_one({_id: 2}, session: session)
}
session.abort_transaction
This method advances the cluster_time.
NOTE this method is a no-op if the provider cluster time is less than the current cluster time.
This method advances the operation_time.
NOTE this method is a no-op if the provider operation time is less than the current operation time.
This property returns the most recent cluster time seen by this session. If no operations have been executed using this session this value will be null unless advanceClusterTime has been called. This value will also be null when a cluster does not report cluster times.
Commits the currently active transaction in this session.
NOTE Raises an error if this session has no transaction.
client = Mongo::Client.new
session = client.start_session
session.start_transaction
client["db"]["collection"].tap { |collection|
collection.insert_one({_id: 1}, session: session)
collection.insert_one({_id: 2}, session: session)
}
session.commit_transaction
Options for the current transaction.
This property returns the operation time of the most recent operation performed using this session. If no operations have been performed using this session the value will be null unless advanceOperationTime has been called. This value will also be null when the cluster does not report operation times.
The recoveryToken field enables the driver to recover a sharded transaction's outcome on a new mongos when the original mongos is no longer available.
The recoveryToken field enables the driver to recover a sharded transaction's outcome on a new mongos when the original mongos is no longer available.
Server description if the session is pinned to a specific mongos.
Starts a new transaction with the given options.
This session's options.default_transaction_options
of type TransactionOptions
is used when options is omitted.
NOTE Raises an error if this session is already in a transaction.
client = Mongo::Client.new
session = client.start_session
# transaction options arguments are optional
session.start_transaction(
read_concern: Mongo::ReadConcern.new(level: "snapshot"),
write_concern: Mongo::WriteConcern.new(w: "majority")
)
Same as #start_transaction
but will commit the transaction after the block returns.
NOTE If an error is thrown, the transaction will be aborted.
client = Mongo::Client.new
session = client.start_session
session.with_transaction {
client["db"]["collection"].tap { |collection|
collection.insert_one({_id: 1}, session: session)
collection.insert_one({_id: 2}, session: session)
}
}