3

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 ?

Selvakumar Ponnusamy
  • 5,363
  • 7
  • 40
  • 78

1 Answers1

5

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.

kevinadi
  • 13,365
  • 3
  • 33
  • 49
  • 3
    Please be aware that `snapshot` isolation is the *best* isolation that could be achieved using MongoDB transactions, **but not with the default settings!** To achieve it, you must set `readConcern=snapshot` and `writeConcern=majority` *on connection string/session/transaction* (but not on database/collection/operation as under a transaction database/collection/operation concern settings are ignored). See https://jepsen.io/analyses/mongodb-4.2.6 – Roman Puchkovskiy Apr 05 '21 at 15:01