没有显式事务支持的 MongoOperations 的默认提交行为
Default Commit behavior of MongoOperations without explicit Transaction Support
如果使用 @Autowired MongoOperations
而不使用 @Transactional
并且代码中没有显式 MongoTransactionManager
Bean 初始化,spring-data-mongodb
中的默认提交行为是什么?
我们可以看到 MongoTxnMgr 是否与 @Transaction 支持一起使用,autocommit:false
在日志的 org.mongodb.driver.protocol.command
中可见,之后是显式的 commitTransaction
;
然而,当它不被使用时,autocommit
不在同一个命令中。在这种情况下,commit
究竟发生在什么时候?
我们正在使用 Mongo 4.X 服务器,spring-data-mongodb 2.2.5 RELEASE
中阐明了使用或不使用显式事务机制从客户端角度来看的 MongoDB 4.X 行为
摘录 - 对于 MongoDB 4.X
for a user you should consider that any write outside of the transaction is autocommited by default. So each atomic write is either fully stored or discarded.
如果使用 @Autowired MongoOperations
而不使用 @Transactional
并且代码中没有显式 MongoTransactionManager
Bean 初始化,spring-data-mongodb
中的默认提交行为是什么?
我们可以看到 MongoTxnMgr 是否与 @Transaction 支持一起使用,autocommit:false
在日志的 org.mongodb.driver.protocol.command
中可见,之后是显式的 commitTransaction
;
然而,当它不被使用时,autocommit
不在同一个命令中。在这种情况下,commit
究竟发生在什么时候?
我们正在使用 Mongo 4.X 服务器,spring-data-mongodb 2.2.5 RELEASE
摘录 - 对于 MongoDB 4.X
for a user you should consider that any write outside of the transaction is autocommited by default. So each atomic write is either fully stored or discarded.