Skip to content

Commit f87b53f

Browse files
fix: address Neal's comments pt 3
1 parent 9c1f665 commit f87b53f

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

src/change_stream.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -577,35 +577,23 @@ function setIsIterator<TSchema>(changeStream: ChangeStream<TSchema>): void {
577577
changeStream[kMode] = 'iterator';
578578
}
579579

580-
function applyKnownOptions(source: Document, options: ReadonlyArray<string>) {
581-
const result: Document = {};
582-
583-
for (const option of options) {
584-
if (source[option]) {
585-
result[option] = source[option];
586-
}
587-
}
588-
589-
return result;
590-
}
591-
592580
/**
593581
* Create a new change stream cursor based on self's configuration
594582
* @internal
595583
*/
596584
function createChangeStreamCursor<TSchema>(
597585
changeStream: ChangeStream<TSchema>,
598-
changeStreamOptions: ChangeStreamOptions | ResumeOptions
586+
options: ChangeStreamOptions | ResumeOptions
599587
): ChangeStreamCursor<TSchema> {
600-
const changeStreamStageOptions = applyKnownOptions(changeStreamOptions, CHANGE_STREAM_OPTIONS);
588+
const changeStreamStageOptions = applyKnownOptions(options, CHANGE_STREAM_OPTIONS);
589+
if (changeStream.type === CHANGE_DOMAIN_TYPES.CLUSTER) {
590+
changeStreamStageOptions.allChangesForCluster = true;
591+
}
601592
const pipeline = [{ $changeStream: changeStreamStageOptions } as Document].concat(
602593
changeStream.pipeline
603594
);
604595

605-
const cursorOptions: ChangeStreamCursorOptions = applyKnownOptions(
606-
changeStreamOptions,
607-
CURSOR_OPTIONS
608-
);
596+
const cursorOptions: ChangeStreamCursorOptions = applyKnownOptions(options, CURSOR_OPTIONS);
609597

610598
const changeStreamCursor = new ChangeStreamCursor<TSchema>(
611599
getTopology(changeStream.parent),
@@ -625,6 +613,17 @@ function createChangeStreamCursor<TSchema>(
625613
return changeStreamCursor;
626614
}
627615

616+
function applyKnownOptions(source: Document, options: ReadonlyArray<string>) {
617+
const result: Document = {};
618+
619+
for (const option of options) {
620+
if (source[option]) {
621+
result[option] = source[option];
622+
}
623+
}
624+
625+
return result;
626+
}
628627
interface TopologyWaitOptions {
629628
start?: number;
630629
timeout?: number;

test/integration/change-streams/change_stream.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ describe('Change Streams', function () {
207207
it('sets fullDocument to `undefined` if no value is passed', function () {
208208
const changeStream = client.watch();
209209

210-
expect(changeStream).to.have.nested.property(
211-
'cursor.pipeline[0].$changeStream.fullDocument',
212-
undefined
210+
expect(changeStream).not.to.have.nested.property(
211+
'cursor.pipeline[0].$changeStream.fullDocument'
213212
);
214213
});
215214

0 commit comments

Comments
 (0)