@@ -20,7 +20,7 @@ import type { AggregateOptions } from './operations/aggregate';
2020import type { OperationParent } from './operations/command' ;
2121import type { ServerSessionId } from './sessions' ;
2222import { CSOTTimeoutContext , type TimeoutContext } from './timeout' ;
23- import { getTopology , type MongoDBNamespace , squashError } from './utils' ;
23+ import { type AnyOptions , getTopology , type MongoDBNamespace , squashError } from './utils' ;
2424
2525const CHANGE_DOMAIN_TYPES = {
2626 COLLECTION : Symbol ( 'Collection' ) ,
@@ -34,6 +34,34 @@ const NO_RESUME_TOKEN_ERROR =
3434 'A change stream document has been received that lacks a resume token (_id).' ;
3535const CHANGESTREAM_CLOSED_ERROR = 'ChangeStream is closed' ;
3636
37+ const INVALID_STAGE_OPTIONS = [
38+ 'raw' ,
39+ 'useBigInt64' ,
40+ 'promoteLongs' ,
41+ 'promoteValues' ,
42+ 'promoteBuffers' ,
43+ 'ignoreUndefined' ,
44+ 'bsonRegExp' ,
45+ 'serializeFunctions' ,
46+ 'fieldsAsRaw' ,
47+ 'enableUtf8Validation' ,
48+ 'timeoutMS' ,
49+ 'readPreference'
50+ ] ;
51+
52+ export function filterOutOptions ( options : AnyOptions , names : ReadonlyArray < string > ) : AnyOptions {
53+ const filterOptions : AnyOptions = { } ;
54+
55+ for ( const name in options ) {
56+ if ( ! names . includes ( name ) ) {
57+ filterOptions [ name ] = options [ name ] ;
58+ }
59+ }
60+
61+ // Filtered options
62+ return filterOptions ;
63+ }
64+
3765/**
3866 * Represents the logical starting point for a new ChangeStream or resuming a ChangeStream on the server.
3967 * @see https://www.mongodb.com/docs/manual/changeStreams/#std-label-change-stream-resume
@@ -891,7 +919,7 @@ export class ChangeStream<
891919 private _createChangeStreamCursor (
892920 options : ChangeStreamOptions | ChangeStreamCursorOptions
893921 ) : ChangeStreamCursor < TSchema , TChange > {
894- const changeStreamStageOptions : Document = { ... options } ;
922+ const changeStreamStageOptions : Document = filterOutOptions ( options , INVALID_STAGE_OPTIONS ) ;
895923 if ( this . type === CHANGE_DOMAIN_TYPES . CLUSTER ) {
896924 changeStreamStageOptions . allChangesForCluster = true ;
897925 }
0 commit comments