feat(database): stream live document updates over admin sockets - #1601
Open
JohnChantz wants to merge 4 commits into
Open
feat(database): stream live document updates over admin sockets#1601JohnChantz wants to merge 4 commits into
JohnChantz wants to merge 4 commits into
Conversation
This was referenced Sep 11, 2026
Contributor
Author
kkopanidis
added this pull request to stack #1603
September 11, 2026 17:43
MongoDB change streams require a replica set, so local Compose now initializes a single-node rs0. Schemas can opt in via realtime.enabled.
Mongo 4.4 keyfiles reject hyphens, and rs.status() returns ok:0 instead of throwing, so Compose never elected a primary for replicaSet URIs.
Stop duplicate admin/router deliveries and apply handshake auth on connect. Retry change-stream leadership after lock races.
kkopanidis
force-pushed
the
feat/database-realtime-mongo
branch
from
September 11, 2026 17:44
ef112bf to
3458413
Compare
| function extractDocumentId(id: unknown): string | null { | ||
| if (id === undefined || id === null) return null; | ||
| if (typeof id === 'string' || typeof id === 'number') return String(id); | ||
| if (typeof id === 'object' && id !== null && 'toHexString' in id) { |
| const hex = (id as { toHexString: () => string }).toHexString(); | ||
| return typeof hex === 'string' && hex.length > 0 ? hex : null; | ||
| } | ||
| if (typeof id === 'object' && id !== null && 'toString' in id) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
Local Compose Mongo now runs as a single-node replica set (
rs0) so change streams work. Existing deployments are unchanged; localDB_CONN_URImust includereplicaSet=rs0.The PR fulfills these requirements:
mainbranchfix #xxx, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Split from #1594 (2/3). Stacked on #1600 (event relays). SQL live updates follow in a stacked PR.
Schemas can opt in to live document updates via
realtime.enabledplusmodelOptions.conduit.realtime.enabled. MongoDB change streams require a replica set, so local Compose initializes a single-noders0. Events arechangemetadata only (no document fields); consumers refetch through authorized REST. Admin clients usePOST /realtime/ticketfor a 30-second handshake token so session JWTs / masterkey are not sent from the browser.Hermes isolates Redis adapter streams by port so admin and router Socket.IO servers do not deliver the same change twice, and handshake auth runs on connect.
Test plan
modules/database/src/realtime/__tests__/, excluding integration): coordinator, authorize, topology, subscriptions, rooms, normalize, statuspackages/core/src/admin/realtime/*.test.ts): ticket, handshake, namespaceapplySocketGlobalMiddlewarestestsdocker compose --profile mongodb up: Mongo becomes replica setrs0;DB_CONN_URIincludesreplicaSet=rs0realtime.enabled, opt a schema in, subscribe on/database/, mutate a document, confirm achangeevent with no document payloadPOST /realtime/ticket(session JWT / masterkey not sent from the browser)