MongoDurableStateStore
Ce contenu n’est pas encore disponible dans votre langue.
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 === 0→insertOne. 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_idreject the duplicate is both shorter and race-free.expectedRevision > 0→updateOne({ _id, revision: expected }). The revision is part of the filter, so a mismatch matches nothing —matchedCount === 0means the stored revision diverged. This is the compare-and-swap the issue’sfindOneAndUpdatesketch 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.
Extends
Section titled “Extends”Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MongoDurableStateStore(
options?):MongoDurableStateStore
Defined in: src/persistence/durable-state-stores/MongoDurableStateStore.ts:58
Parameters
Section titled “Parameters”options?
Section titled “options?”MongoDurableStateStoreOptions = {}
Returns
Section titled “Returns”MongoDurableStateStore
Overrides
Section titled “Overrides”MongoStore.constructor
Methods
Section titled “Methods”close()
Section titled “close()”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.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”delete()
Section titled “delete()”delete(
persistenceId):Promise<void>
Defined in: src/persistence/durable-state-stores/MongoDurableStateStore.ts:134
Remove the record entirely. Idempotent.
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”load()
Section titled “load()”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.
Type Parameters
Section titled “Type Parameters”S
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
_options?
Section titled “_options?”PersistenceOptions
Returns
Section titled “Returns”Promise<Option<DurableStateRecord<S>>>
Implementation of
Section titled “Implementation of”upsert()
Section titled “upsert()”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.
Type Parameters
Section titled “Type Parameters”S
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
expectedRevision
Section titled “expectedRevision”number
S
_options?
Section titled “_options?”PersistenceOptions
Returns
Section titled “Returns”Promise<DurableStateRecord<S>>
