Skip to content

feat(database): stream live document updates over admin sockets - #1601

Open
JohnChantz wants to merge 4 commits into
feat/router-event-relaysfrom
feat/database-realtime-mongo
Open

feat(database): stream live document updates over admin sockets#1601
JohnChantz wants to merge 4 commits into
feat/router-event-relaysfrom
feat/database-realtime-mongo

Conversation

@JohnChantz

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other (please describe)

Does this PR introduce a breaking change?

  • Yes
  • No

Local Compose Mongo now runs as a single-node replica set (rs0) so change streams work. Existing deployments are unchanged; local DB_CONN_URI must include replicaSet=rs0.

The PR fulfills these requirements:

  • It's submitted to the main branch
  • When resolving a specific issue, it's referenced in the PR's description (e.g. fix #xxx, where "xxx" is the issue number)

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature

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.enabled plus modelOptions.conduit.realtime.enabled. MongoDB change streams require a replica set, so local Compose initializes a single-node rs0. Events are change metadata only (no document fields); consumers refetch through authorized REST. Admin clients use POST /realtime/ticket for 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

  • Database realtime unit tests (modules/database/src/realtime/__tests__/, excluding integration): coordinator, authorize, topology, subscriptions, rooms, normalize, status
  • Core admin realtime tests (packages/core/src/admin/realtime/*.test.ts): ticket, handshake, namespace
  • Hermes applySocketGlobalMiddlewares tests
  • docker compose --profile mongodb up: Mongo becomes replica set rs0; DB_CONN_URI includes replicaSet=rs0
  • Enable realtime.enabled, opt a schema in, subscribe on /database/, mutate a document, confirm a change event with no document payload
  • Admin socket via POST /realtime/ticket (session JWT / masterkey not sent from the browser)

@JohnChantz

Copy link
Copy Markdown
Contributor Author

Stack: #1600 (event relays) → this PR → #1602 (SQL live updates). Split from #1594.

@kkopanidis
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
kkopanidis force-pushed the feat/database-realtime-mongo branch from ef112bf to 3458413 Compare September 11, 2026 17:44
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) {
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