Basic

  • Start a session

session = client.start_session()
session.end_session()
  • You can use it instead of above in Python.

with client.start_session() as s:
    pass
  • You can start, commit, abort a transaction

session.start_transaction()
session.commit_transaction()
session.abort_transaction()
  • Just pass a session argument with CURD Syntax

col.insert_one({'_id': 0}, session=session)
col.find({}, session=session)
collection.update_one({'_id': 1}, {'$set': {'x': 10}}, session=session)
collection.delete_many({'_id': 2}, session=session)

Last updated