Why replica set is mandatory for transactions in MongoDB?

As per MongoDB documentation, transactions only works for replica sets and not single node. Why such requirement? Isn’t it is easier to do transaction stuff on a single node rather than a distributed system?

Hi @Rajat_Goel,

Since transactions are built on concepts of logical sessions they require mecahnics (like oplog) which are only available in replica set environment.

You can always convert a standalone to a single noded replica set and transactions will work with this one node.

https://docs.mongodb.com/manual/tutorial/convert-standalone-to-replica-set/

Best
Pavel

2 Likes