Transaction support in MongoDB

后端 未结 8 1766
刺人心
刺人心 2020-12-10 02:02

I am new to MongoDB. I read that MongoDB does not support multi-document transactionshere http://docs.mongodb.org/manual/faq/fundamentals/.

If I want to

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 02:47

    MongoDB does not support transactions as in Relational DB. ACID postulates in transactions is a complete different functionality provided by storage engines in MySQL

    Some of the features of InnoDB engine in MySQL:

    • Crash Recovery
    • Double write buffer
    • Auto commit settings
    • Isolation Level

    This is what MongoDB community has to say:

    MongoDB does not have support for traditional locking or complex transactions with rollback.

    MongoDB aims to be lightweight, fast, and predictable in its performance. By keeping transaction support extremely simple, MongoDB can provide greater performance especially for partitioned or replicated systems with a number of database server processes.

    The purpose of a transaction is to make sure that the whole database stays consistent while multiple operations take place.

    But in contrary to most relational databases, MongoDB isn't designed to run on a single host. It is designed to be set up as a cluster of multiple shards where each shard is a replica-sets of multiple servers (optionally at different geographical locations).

    But if you are still looking for way to make transactions possible:

    • Try using document level atomicity provided by mongo
    • two phase commit in Mongo provides simple transaction mechanism for basic operations
    • mongomvcc is built on the top of mongo and also supports transaction as they say
    • Hybrid of MySQL and Mongo

提交回复
热议问题