Search code examples
mongodbtransactionsisolation-level

Changing MongoDB Isolation level when Mongo Sessions involved


Whats is the default Isolation level for MongoDB4.0 when transactions are used.

One Document say READ UNCOMMITTED is default isolation level.https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/

Another document says snapshot is default isolation level when transaction are used. https://www.percona.com/blog/2018/06/25/mongodb-transactions-your-very-first-transaction-with-mongodb-4-0/

Which one is correct? Is it possible to change it ?


Solution

  • MongoDB allows the client to determine the required isolation level depending on requirements via a combination of write concern, read concern, and the use of sessions.

    With regard to transactions (which requires the use of sessions), the default isolation is snapshot.

    Read uncommitted is the default isolation level without the use of sessions, as per Read Isolation, Consistency, and Recency.

    It is possible to customize the read & write concerns of a transaction. See:

    Unless you have a specific use case requiring specific isolation levels, it's best to leave this setting as default.