abortTransaction

On this page本页内容

Definition定义

abortTransaction

New in version 4.0.在版本4.0中新增

Terminates the multi-document transaction and rolls back any data changes made by the operations within the transaction. 终止多文档事务并回滚事务中操作所做的任何数据更改。That is, the transaction ends without saving any of the changes made by the operations in the transaction.也就是说,事务结束时不保存事务中操作所做的任何更改。

To run the abortTransaction, the command must be run against the admin database and run within a Session(). 要运行abortTransaction,必须对admin数据库运行该命令,并在Session()中运行。Rather than run the abortTransaction command directly, most users should use the driver method or the mongosh Session.abortTransaction() helper.大多数用户应该使用驱动程序方法或mongosh Session.abortTransaction()助手,而不是直接运行abortTransaction命令。

The command has the following syntax:该命令具有以下语法:

{
  abortTransaction: 1,
  txnNumber: <long>,
  writeConcern: <document>,
  autocommit: false,
  comment: <any>
}

Behavior行为

Atomicity原子性

When a transaction aborts, all data changes made by the writes in the transaction are discarded without ever becoming visible and the transaction ends.当事务中止时,事务中写入所做的所有数据更改都将被丢弃,而不再可见,事务结束。

Security安全

If running with auditing, operations in an aborted transaction are still audited.如果使用审核运行,则中止事务中的操作仍将被审核。

←  Sessions CommandscommitTransaction →