MotorClientSession
– Sequence of operations¶
-
class
motor.motor_tornado.
MotorClientSession
(delegate, motor_client)¶ A session for ordering sequential operations.
Do not create an instance of
MotorClientSession
directly; useMotorClient.start_session()
:collection = client.db.collection async with await client.start_session() as s: async with s.start_transaction(): await collection.delete_one({'x': 1}, session=s) await collection.insert_one({'x': 2}, session=s)
New in version 2.0.
-
coroutine
abort_transaction
()¶ Abort a multi-statement transaction.
-
coroutine
commit_transaction
()¶ Commit a multi-statement transaction.
-
coroutine
end_session
()¶ Finish this session. If a transaction has started, abort it.
It is an error to use the session after the session has ended.
-
start_transaction
(read_concern=None, write_concern=None, read_preference=None)¶ Start a multi-statement transaction.
Takes the same arguments as
TransactionOptions
.Best used in a context manager block:
# Use "await" for start_session, but not for start_transaction. async with await client.start_session() as s: async with s.start_transaction(): await collection.delete_one({'x': 1}, session=s) await collection.insert_one({'x': 2}, session=s)
-
advance_cluster_time
¶ Update the cluster time for this session.
Parameters: - cluster_time: The
cluster_time
from another ClientSession instance.
- cluster_time: The
-
advance_operation_time
¶ Update the operation time for this session.
Parameters: - operation_time: The
operation_time
from another ClientSession instance.
- operation_time: The
-
client
¶ The
MotorClient
this session was created from.
-
cluster_time
¶ The cluster time returned by the last operation executed in this session.
-
has_ended
¶ True if this session is finished.
-
operation_time
¶ The operation time returned by the last operation executed in this session.
-
options
¶ The
SessionOptions
this session was created with.
-
session_id
¶ A BSON document, the opaque server session identifier.
-
coroutine