Exercises

Exercise 1

  • Suggest that which documents are not inserted

without_transaction.py
col.insert_one({'_id': 0})
col.insert_one({'_id': 1})
col.insert_one({'_id': 1})
col.insert_one({'_id': 2})
with_transaction.py
with client.start_session() as s:
    s.start_transaction()
    
    col.insert_one({"_id" : 0}, session=s)
    col.insert_one({"_id" : 1}, session=s)
    col.insert_one({"_id" : 1}, session=s)
    col.insert_one({"_id" : 2}, session=s)
    
    s.commit_transaction()

Last updated