Pular para o conteúdo
Português (BR)

MongoDurableStateStore

Este conteúdo não está disponível em sua língua ainda.

Defined in: src/persistence/durable-state-stores/MongoDurableStateStore.ts:53

DurableStateStore backed by MongoDB — the “event-free” cousin of event sourcing, one document per persistence id rewritten in place.

The persistence id is the document _id, so uniqueness comes from the index MongoDB creates for free and there is no secondary index to maintain. Optimistic concurrency rides on the revision field:

  • expectedRevision === 0insertOne. A collision is server error 11000, which is the natural fit here: MongoDB has no “insert if absent” that reports zero affected rows, and letting _id reject the duplicate is both shorter and race-free.
  • expectedRevision > 0updateOne({ _id, revision: expected }). The revision is part of the filter, so a mismatch matches nothing — matchedCount === 0 means the stored revision diverged. This is the compare-and-swap the issue’s findOneAndUpdate sketch describes, in the form that needs no round-trip for the old document.

Either way the current revision is read back so the error reports what the caller actually raced against.

new MongoDurableStateStore(options?): MongoDurableStateStore

Defined in: src/persistence/durable-state-stores/MongoDurableStateStore.ts:58

MongoDurableStateStoreOptions = {}

MongoDurableStateStore

MongoStore.constructor

close(): Promise<void>

Defined in: src/persistence/LazyStore.ts:66

Best-effort teardown; idempotent.

Journal and SnapshotStore have carried this since they were written; DurableStateStore was the one contract of the three without it, even though its implementations hold exactly the same kind of resource — a connection pool, an HTTP client, a SQLite file handle. Callers that own a store therefore had no contractual way to release it, and the test suite leaned on closeQuietly probing for the method.

Promise<void>

DurableStateStore.close

MongoStore.close


delete(persistenceId): Promise<void>

Defined in: src/persistence/durable-state-stores/MongoDurableStateStore.ts:134

Remove the record entirely. Idempotent.

string

Promise<void>

DurableStateStore.delete


load<S>(persistenceId, _options?): Promise<Option<DurableStateRecord<S>>>

Defined in: src/persistence/durable-state-stores/MongoDurableStateStore.ts:122

Load the latest record for persistenceId, or None if none exists. options.encryption is required when client-side encryption was used at write time.

S

string

PersistenceOptions

Promise<Option<DurableStateRecord<S>>>

DurableStateStore.load


upsert<S>(persistenceId, expectedRevision, state, _options?): Promise<DurableStateRecord<S>>

Defined in: src/persistence/durable-state-stores/MongoDurableStateStore.ts:73

Upsert the state for persistenceId. expectedRevision must match the current stored revision (0 when no record exists yet). Throws DurableStateConcurrencyError on conflict. Optional options carry per-call preferences from the caller (e.g. compression / encryption set on the actor); stores that cannot honour them silently ignore the field.

S

string

number

S

PersistenceOptions

Promise<DurableStateRecord<S>>

DurableStateStore.upsert