Are the change events of a transaction always guaranteed to appear in the order in which they are executed?

Are the change events of a transaction always guaranteed to appear in the order in which they are executed? For example, if two concurrent transactions are being executed, the below sequence shows the order of the operations being maintained even if the transactions themselves are not grouped together.

txn1 - operation1
txn1 - operation2
txn2 - operation1
txn1 - operation3
txn1 - operation4
txn2 - operation2
txn2 - operation3
txn2 - operation4
Is there a possibility of the change events appearing as:

txn1 - operation1
txn1 - operation2
txn2 - operation1
txn1 - operation4
txn1 - operation3
txn2 - operation4
txn2 - operation3
txn2 - operation2

@Kiruphasankaran_Nataraj
In MongoDB, the order of operations within a single transaction is guaranteed to be maintained. However, the order of operations across multiple concurrent transactions is not guaranteed to be maintained. In other words, if two transactions are executed concurrently, the order in which the change events for each transaction appear in the database may not match the order in which the operations were executed. This is because MongoDB uses a multi-version concurrency control (MVCC) model which allows multiple transactions to execute concurrently and make changes to the same data, and the resulting order of operations may depend on the specific timing and order of those changes.

1 Like