Mongodb4.0 transaction rollback problem

follow the example on the Internet to write that you can"t roll back?

db.col.find ()
{"_ id": ObjectId ("5b845237d63ff6fb1220861c"), "name": "ccy"}
{"_ id": ObjectId ("5b8453f5cf6edbf8ffc60a95"), "name": "ssy"}
{"_ id": ObjectId ("5b8456dcf580719bba707dc1"), "name": "ccc"}

s = db.getMongo (). StartSession ()
session {"id": UUID ("33f4e714-a59d-4e83-8750-011bb0b9d637")}
s.startTransaction ()
db.col.insert ({name: "mongo"})
WriteResult ({"nInserted": 1})
s.abortTransaction ()
db.col.find ()
{"_ id": ObjectId ("5b845237d63ff6fb1220861c"), "name": "ccy"}
{"_ id": ObjectId ("5b8453f5cf6edbf8ffc60a95"), "name": "ssy"}
{"_ id": ObjectId ("5b8456dcf580719bba707dc1"), "name": "ccc"}
{"_ id": ObjectId ("5b8458e726a5a62d9970c900"), "name": "mongo"}

as shown in the figure, a transaction is opened, a day"s data is inserted, and the transaction is rolled back. But the data is still plugged in?
ask the god why


maybe the example you read is incorrect.
from a design point of view, your session has nothing to do with the db.col collection. How does the system know how this session works on this collection? In the real environment, there will be multiple session, multiple sets, the system must have a certain way to know the corresponding relationship, so the current writing method is definitely inappropriate. The correct way to write it is:

  Session.startTransaction  

Menu