-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(NODE-4192): make MongoClient.connect optional #3232
Changes from 5 commits
ab10b7d
c114b30
bb88b29
1a9efa8
1e90d81
912799b
da6392e
6296ade
758103e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,8 +600,24 @@ export class ChangeStream< | |
|
||
const cursorOptions: ChangeStreamCursorOptions = filterOptions(options, CURSOR_OPTIONS); | ||
|
||
const client: MongoClient | null = | ||
this.type === CHANGE_DOMAIN_TYPES.CLUSTER | ||
? (this.parent as MongoClient) | ||
: this.type === CHANGE_DOMAIN_TYPES.DATABASE | ||
? (this.parent as Db).s.client | ||
: this.type === CHANGE_DOMAIN_TYPES.COLLECTION | ||
? (this.parent as Collection).s.db.s.client | ||
: null; | ||
|
||
if (client == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question(s): even though this error should never be thrown, in theory _createChangeStreamCursor now throws.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add a test, the thing is this is unreachable because the constructor will throw if one of these three symbols isn't used. This is one of those fatal errors where something quite unexpected has occurred. The test would be making a change stream and then reaching in an changing the type? I can do that, would that make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's a fair point. I'll leave this thread open for additional reviews for context. |
||
// This should never happen because of the assertion in the constructor | ||
throw new MongoRuntimeError( | ||
`Changestream type should only be one of cluster, database, collection. Found ${this.type.toString()}` | ||
); | ||
} | ||
|
||
const changeStreamCursor = new ChangeStreamCursor<TSchema, TChange>( | ||
getTopology(this.parent), | ||
client, | ||
this.namespace, | ||
pipeline, | ||
cursorOptions | ||
|
@@ -835,12 +851,12 @@ export class ChangeStreamCursor< | |
pipeline: Document[]; | ||
|
||
constructor( | ||
topology: Topology, | ||
client: MongoClient, | ||
namespace: MongoDBNamespace, | ||
pipeline: Document[] = [], | ||
options: ChangeStreamCursorOptions = {} | ||
) { | ||
super(topology, namespace, options); | ||
super(client, namespace, options); | ||
|
||
this.pipeline = pipeline; | ||
this.options = options; | ||
|
@@ -907,7 +923,7 @@ export class ChangeStreamCursor< | |
} | ||
|
||
clone(): AbstractCursor<TChange> { | ||
return new ChangeStreamCursor(this.topology, this.namespace, this.pipeline, { | ||
return new ChangeStreamCursor(this.client, this.namespace, this.pipeline, { | ||
...this.cursorOptions | ||
}); | ||
} | ||
|
@@ -920,7 +936,7 @@ export class ChangeStreamCursor< | |
}); | ||
|
||
executeOperation<TODO_NODE_3286, ChangeStreamAggregateRawResult<TChange>>( | ||
session, | ||
session.client, | ||
aggregateOperation, | ||
(err, response) => { | ||
if (err || response == null) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like while we are here, all the times we access the internal states to get the client we could just add a getter or method for it so that if in the future we change the way the internal states are represented we only have to change the client access in a single place. So instead of
this.s.db.client
everywhere we may have athis.client
orthis.getClient()
. (Same forthis.s.client
). Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chatted offline, we'll likely clean this up later for now, TS will protect against us making changes here and we can apply some sweeping change later using that hinting