Skip to content

Fold mutations of one MongoDB record into one write - #166

Merged
liran merged 6 commits into
mainfrom
feat/fold-mongodb-mutations
Nov 8, 2026
Merged

liran merged 6 commits into
mainfrom
feat/fold-mongodb-mutations

Conversation

@liran

@liran liran commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

MongoDB now folds queued mutations of one record the way Search does since #165, so a client that keeps rewriting the same records stops queueing behind itself. Puts and deletes of a record collapse to the last of them, and Lua programs of a record run in order on the transaction's single read with one write per record; creates, replaces and backend expressions still run one at a time.

Each mutation keeps its own result: a program whose caller leaves before the write is left out and the chain is evaluated again, programs rejected on a document only a failed commit would have made real fail with it, and only a rejected document replays the chain one mutation at a time.

@liran liran self-assigned this Nov 8, 2026
liran added 2 commits November 8, 2026 11:52
Write one op per program that changes the record, in order, in the
chain's transaction, so validators and unique indexes see each document
as they would one program at a time. Unfold a chain too large for one
command, report NOT_APPLIED rather than NOT_STARTED in a replay, give
every folded put a result when no session starts, and split a write only
when more than one remains after folding.
A program whose caller left before the batch reports NOT_STARTED and
joins no chain, and a chain without a live caller ends at once, so it
never reaches MongoDB. The docs say MongoDB writes each changed document
in one ordered bulkWrite.
@liran
liran merged commit db27d25 into main Nov 8, 2026
8 checks passed
@liran
liran deleted the feat/fold-mongodb-mutations branch November 8, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant