定义
abortTransaction终止多文档事务并回滚事务内操作所做的任何数据更改。也就是说,事务结束时不会保存事务中操作所做的任何更改。
提示
In
mongosh, this command can also be run through theSession.abortTransaction()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.To run the
abortTransaction, the command must be run against theadmindatabase and run within aSession().
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.adminCommand( { abortTransaction: 1, txnNumber: <long>, writeConcern: <document>, autocommit: false, comment: <any> } )
行为
原子性(Atomicity)
当事务中止时,事务中通过写入进行的所有数据更改都会丢弃且变得不可见,同时事务结束。
安全性
如果以审核方式运行,中止的事务中的操作仍会被审核。