#include <userver/storages/mongo/transaction.hpp>
MongoDB transaction handle that provides ACID guarantees.
Transactions group multiple operations within logical units of work and provide ACID guarantees. All operations in a transaction either succeed completely or fail completely.
Definition at line 33 of file transaction.hpp.
Public Types | |
| enum class | State { kNone , kInProgress , kCommitted , kAborted } |
| Get the transaction state. More... | |
Public Member Functions | |
| Transaction () | |
| Creates invalid transaction. | |
| Transaction (Transaction &&) noexcept | |
| Move constructor. | |
| Transaction & | operator= (Transaction &&) noexcept |
| Move assignment operator. | |
| ~Transaction () | |
| Destructor. Aborts transaction if not committed. | |
| Collection | GetCollection (std::string name) |
| Get a collection handle within the transaction context. | |
| void | Commit () |
| Commit the transaction. | |
| void | Abort () noexcept |
| Abort the transaction. | |
| bool | IsActive () const noexcept |
| Check if transaction is active. | |
| State | GetState () const noexcept |
| Get current transaction state. | |
|
strong |
Get the transaction state.
| Enumerator | |
|---|---|
| kNone | Transaction not started. |
| kInProgress | Transaction is active. |
| kCommitted | Transaction has been committed. |
| kAborted | Transaction has been aborted. |
Definition at line 77 of file transaction.hpp.
|
noexcept |
Abort the transaction.
Discards all changes made within the transaction. This method is idempotent and safe to call multiple times.
| void storages::mongo::Transaction::Commit | ( | ) |
Commit the transaction.
Makes all changes within the transaction permanent and visible to other operations. If the transaction fails to commit, an exception will be thrown.
| MongoException | on commit failure |
| Collection storages::mongo::Transaction::GetCollection | ( | std::string | name | ) |
Get a collection handle within the transaction context.
| name | collection name |
|
noexcept |
Check if transaction is active.