KOVA
Docs

Transactions

Several writes on one collection commit together, or none of them do.

A transaction names the collection whose partition owns it. Later inserts, finds, updates, deletes, counts, and aggregates on that collection pass the same txnId. A collection that hashes to another partition does not see the transaction. Commit and abort name the same collection.

Uncommitted writes stay off the pages. Commit is one log record, so a crash publishes every write in the transaction or none of them. Abort discards them. With a replica set, followers receive that one commit record and apply it. They do not open the transaction. Abort writes nothing to the oplog.

A short session

db.runCommand({
  beginTransaction: 1,
  collection: "orders",
  txnId: NumberLong(1),
  isolation: "snapshot"
})
db.runCommand({
  insert: "orders",
  documents: [{ sku: "kettle", qty: 1 }],
  txnId: NumberLong(1)
})
db.runCommand({
  commitTransaction: 1,
  collection: "orders",
  txnId: NumberLong(1)
})

abortTransaction takes the same collection and txnId. Another client’s find sees the kettle only after commit.

$out inside a transaction is refused. mapReduce with txnId is refused. A transaction on a shard router is refused: the router does not own the documents.

Isolation

The default is snapshot. Pass isolation on begin.

NameWhat a statement sees
readUncommittedThe latest pages, including other transactions' writes that are not committed yet.
readCommittedThe latest committed version, taken again on each statement.
repeatableReadA stable view of the rows this transaction has read.
snapshotThe database as of the moment the transaction began.
serializableThe snapshot, and the transaction aborts when a document it read was committed by someone else.

Two transactions that write the same document: the later commit aborts. timeoutMs: 0 expires the transaction on its next statement. Omit the timeout and the transaction waits until you commit or abort.

On a replica set

Begin, each staged statement, and abort stay on the primary. Commit proposes one oplog entry, applyTransaction, carrying the writes. Followers apply that entry as one log record. An arbiter stores the entry and applies no documents. With no [replication] section, commit is the local log record it always was.