<!-- llms-explorer concept facts · https://llms-explorer.com/tree/pinned-event-mongodb-schema-version-writes-and-notification-failure-boundaries/ · pack 2026-11-02 · ~1613 tokens -->

# Pinned event-mongodb schema version writes and notification failure boundaries

> Source-anchored research for Pinned event-mongodb schema version writes and notification failure boundaries. Run status: COMPLETED.

Parent: [Change Data Capture Patterns](https://llms-explorer.com/tree/change-data-capture-patterns/) · 4 facets · 11 facts · page: https://llms-explorer.com/tree/pinned-event-mongodb-schema-version-writes-and-notification-failure-boundaries/

## Definitions

- The read-check-replace sequence is not a database compare-and-swap on the version: `Get` reads by `_id`, while `p.collection.ReplaceOne` filters only by `_id`. Inference from those predicates: a concurrent writer can replace the record between the check and replacement, so this method alone does not establish atomic monotonic version enforcement. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb.go)

## Problems, failure modes and limitations

- In the pinned implementation, `Set` calls `schema.Validate()` before checking whether the provider is closed. It then calls `p.Get(ctx, schema.Name)` and returns its error. The downgrade predicate is `existing != nil && schema.Version < existing.Version`; equal versions are permitted. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb_test.go)
- After the version check, `Set` converts the supplied schema, assigns `m.UpdatedAt` from `time.Now()`, assigns `m.CreatedAt` for a new record or preserves the existing value, and calls `p.collection.ReplaceOne` with only `_id` in the filter and `options.Replace().SetUpsert(true)`. A replacement error returns before notification. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb.go)
- After a successful replacement, Set constructs a SchemaChangeEvent from Name, Version and the same timestamp, attempts local watcher sends under an RLock using select with a default branch, releases the lock, and invokes a non-nil publisher. A channel that cannot accept the send loses that notification without an error from this loop. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb.go)
- A publisher error is returned directly from Set after the replacement and local watcher-send attempts; the method contains no rollback, retry or persisted pending-notification operation for that error path. This is a source-level control-flow observation, not an executed failure test. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb.go)
- Coverage limit of the two inspected pinned schema test files: neither contains a concurrent version-write assertion, a failing publisher callback scenario, watcher buffer saturation, crash recovery, or durable notification replay. The inspected success fixtures therefore do not establish atomic concurrent-version enforcement or durable notification delivery. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb_integration_test.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb_test.go)

## Comparisons and alternatives

- `Delete` checks the closed flag and calls `p.collection.DeleteOne` using `_id`; it wraps database errors and otherwise returns nil without inspecting the deletion count. Unlike `Set`, its body does not send to local watchers or invoke the publisher. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb.go)

## Facts and statements

- `Watch` rejects a closed provider, creates a local channel with capacity `100`, appends it to `p.watchers`, and starts a goroutine that waits for context cancellation or `p.closeChan`. The goroutine removes the channel under the mutex and closes it. This method does not open a MongoDB change stream or replay persisted notifications. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb.go)
- As source observations, the sequential `TestIntegrationSetVersionDowngrade` fixture sets version `5`, expects `ErrVersionDowngrade` for version `3`, permits another version `5`, and permits version `6`. `TestIntegrationSetPreservesCreatedAt` asserts preserved creation time and advancing update time after sequential writes. These assertions are not execution results from this research pass. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb_integration_test.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb.go)
- As source observations, `TestIntegrationSetGetDelete` checks a missing record, writes a schema, checks retrieved fields and nonzero timestamps, deletes it, and expects a missing record afterward. The unit fixtures separately assert closed-provider guards and rejection of an empty schema name before server interaction; they do not execute those integration operations. (medium confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb_integration_test.go) · [also](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb_test.go)
- The success-path fixture `TestIntegrationPublisherInvokedOnSet` asserts one callback invocation with event name `evt` and version `2`. `TestIntegrationWatchReceivesChange` uses a nil publisher, asserts a local notification for `watched` at version `7`, and checks channel closure after cancellation. These are fixture assertions, not observed test outcomes. (low confidence) — [source](https://raw.githubusercontent.com/rbaliyan/event-mongodb/ca444aedec31e7e959c0932a8f7577c15312f37e/schema/mongodb_integration_test.go)
