From 827ac3a61a5879987619a5d3143bec6132e91231 Mon Sep 17 00:00:00 2001 From: Ry Anderson <60347977+Omnicpie@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:04:26 +0100 Subject: [PATCH 1/2] fix(NODE-4763): tryNext not updating resumeToken for a given update --- src/change_stream.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/change_stream.ts b/src/change_stream.ts index ed847519e8a..ce90464e9d5 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -809,7 +809,8 @@ export class ChangeStream< while (true) { try { const change = await this.cursor.tryNext(); - return change ?? null; + const processedChange = this._processChange(change ?? null); + return processedChange; } catch (error) { try { await this._processErrorIteratorMode(error, this.cursor.id != null); From a9ab3c5cb73b62e45a3578a044bfe846661eed3b Mon Sep 17 00:00:00 2001 From: Ry Anderson <60347977+Omnicpie@users.noreply.github.com> Date: Fri, 18 Jul 2025 13:45:15 +0100 Subject: [PATCH 2/2] fix(NODE-4763): Tweak logic to handle null changes without errors --- src/change_stream.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/change_stream.ts b/src/change_stream.ts index ce90464e9d5..a4718efc931 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -809,7 +809,13 @@ export class ChangeStream< while (true) { try { const change = await this.cursor.tryNext(); - const processedChange = this._processChange(change ?? null); + + // Prevent _processChange from producing an error due to a `null` change + if (!change) { + return null; + } + + const processedChange = this._processChange(change); return processedChange; } catch (error) { try {