mongodb - 为什么MongoDB没有事务? (v4.0 之前)

标签 mongodb transactions

更新:MongoDB 从 4.0 版本开始支持事务。

原始问题:

据我所知,MongoDB不支持事务,并且没有计划实现此类支持。这是什么原因?

最佳答案

没有事务是让 MongoDB 具有可扩展性的一种权衡。

事务的目的是确保在进行多个操作时整个数据库保持一致。但与大多数关系数据库相反,MongoDB 并非设计为在单个主机上运行。它被设计为设置为多个分片的集群,其中每个分片是多个服务器的副本集(可选地位于不同的地理位置)。

事务可能会影响数据库的许多主机。这意味着事务必须在所有这些主机之间同步。这意味着相当大的开销,并且在通过添加更多服务器来增加数据库大小时会非常严重地扩展。

MongoDB FAQ解释如下:

MongoDB does not have support for traditional locking or complex transactions with rollback. MongoDB aims to be lightweight, fast, and predictable in its performance. This is similar to the MySQL MyISAM autocommit model. By keeping transaction support extremely simple, MongoDB can provide greater performance especially for partitioned or replicated systems with a number of database server processes.

关于mongodb - 为什么MongoDB没有事务? (v4.0 之前),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18042255/

相关文章:

MongoDB查询获取CPU使用率

node.js - 如何使用 Nodejs 对从 mongoDB 获取的数据求和

java - RDBMS:执行多项操作的最佳方式是什么

java - 当一个@Transactional 注解的方法被多个实例并行命中时会发生什么?

java - @RetryTransaction : how to make it work when deadlock was found

MongoDB .Net 驱动程序 2.0 Builders Filter(字段到数组比较)

mongodb - 按嵌入文档排序

c++ - 如何使用 C++ 驱动程序处理 MongoDB 中 UserException 的数据类型错误

transactions - 使用事务属性 REQUIRES_NEW 处理另一个 EJB 方法中的异常

java - @Transactional 不会在数据库中生成 INSERT