-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-6472): findOne and find no longer keep open cursors #4580
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
base: main
Are you sure you want to change the base?
Changes from all commits
02a846d
669b82b
8bf5f01
92fb6db
fb6f806
a1693ee
4c006bc
a6bf329
e90b545
823aee5
caf668a
ccfb04a
c56f1ba
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 |
---|---|---|
|
@@ -81,6 +81,16 @@ export interface FindOptions<TSchema extends Document = Document> | |
timeoutMode?: CursorTimeoutMode; | ||
} | ||
|
||
/** @public */ | ||
export interface FindOneOptions extends FindOptions { | ||
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */ | ||
batchSize?: number; | ||
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */ | ||
limit?: number; | ||
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */ | ||
noCursorTimeout?: boolean; | ||
} | ||
|
||
/** @internal */ | ||
export class FindOperation extends CommandOperation<CursorResponse> { | ||
/** | ||
|
@@ -185,17 +195,15 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp | |
|
||
if (typeof options.batchSize === 'number') { | ||
if (options.batchSize < 0) { | ||
if ( | ||
options.limit && | ||
options.limit !== 0 && | ||
Math.abs(options.batchSize) < Math.abs(options.limit) | ||
) { | ||
findCommand.limit = -options.batchSize; | ||
} | ||
|
||
findCommand.singleBatch = true; | ||
findCommand.limit = -options.batchSize; | ||
} else { | ||
findCommand.batchSize = options.batchSize; | ||
if (options.batchSize === options.limit) { | ||
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. the 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. Good call. I've removed it. 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. I also noticed two if-statements above:
We can remove the first nested if-statement there, right? That seems to have been used for find one with the old findOne implementation:
|
||
// Spec dictates that if these are equal the batchSize should be one more than the | ||
// limit to avoid leaving the cursor open. | ||
findCommand.batchSize = options.batchSize + 1; | ||
} else { | ||
findCommand.batchSize = options.batchSize; | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
{ | ||
"description": "findOne", | ||
"schemaVersion": "1.0", | ||
"createEntities": [ | ||
{ | ||
"client": { | ||
"id": "client0", | ||
"observeEvents": [ | ||
"commandStartedEvent" | ||
] | ||
} | ||
}, | ||
{ | ||
"database": { | ||
"id": "database0", | ||
"client": "client0", | ||
"databaseName": "find-tests" | ||
} | ||
}, | ||
{ | ||
"collection": { | ||
"id": "collection0", | ||
"database": "database0", | ||
"collectionName": "coll0" | ||
} | ||
} | ||
], | ||
"initialData": [ | ||
{ | ||
"collectionName": "coll0", | ||
"databaseName": "find-tests", | ||
"documents": [ | ||
{ | ||
"_id": 1, | ||
"x": 11 | ||
}, | ||
{ | ||
"_id": 2, | ||
"x": 22 | ||
}, | ||
{ | ||
"_id": 3, | ||
"x": 33 | ||
}, | ||
{ | ||
"_id": 4, | ||
"x": 44 | ||
}, | ||
{ | ||
"_id": 5, | ||
"x": 55 | ||
}, | ||
{ | ||
"_id": 6, | ||
"x": 66 | ||
} | ||
] | ||
} | ||
], | ||
"tests": [ | ||
{ | ||
"description": "FindOne with filter", | ||
"operations": [ | ||
{ | ||
"object": "collection0", | ||
"name": "findOne", | ||
"arguments": { | ||
"filter": { | ||
"_id": 1 | ||
} | ||
}, | ||
"expectResult": { | ||
"_id": 1, | ||
"x": 11 | ||
} | ||
} | ||
], | ||
"expectEvents": [ | ||
{ | ||
"client": "client0", | ||
"events": [ | ||
{ | ||
"commandStartedEvent": { | ||
"command": { | ||
"find": "coll0", | ||
"filter": { | ||
"_id": 1 | ||
}, | ||
"batchSize": { | ||
"$$exists": false | ||
}, | ||
"limit": 1, | ||
"singleBatch": true | ||
}, | ||
"commandName": "find", | ||
"databaseName": "find-tests" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "FindOne with filter, sort, and skip", | ||
"operations": [ | ||
{ | ||
"object": "collection0", | ||
"name": "findOne", | ||
"arguments": { | ||
"filter": { | ||
"_id": { | ||
"$gt": 2 | ||
} | ||
}, | ||
"sort": { | ||
"_id": 1 | ||
}, | ||
"skip": 2 | ||
}, | ||
"expectResult": { | ||
"_id": 5, | ||
"x": 55 | ||
} | ||
} | ||
], | ||
"expectEvents": [ | ||
{ | ||
"client": "client0", | ||
"events": [ | ||
{ | ||
"commandStartedEvent": { | ||
"command": { | ||
"find": "coll0", | ||
"filter": { | ||
"_id": { | ||
"$gt": 2 | ||
} | ||
}, | ||
"sort": { | ||
"_id": 1 | ||
}, | ||
"skip": 2, | ||
"batchSize": { | ||
"$$exists": false | ||
}, | ||
"limit": 1, | ||
"singleBatch": true | ||
}, | ||
"commandName": "find", | ||
"databaseName": "find-tests" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
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.
Do we have a ticket to remove these fields from
FindOneOptions
in v7?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.
We'd need to add this to the bucket deprecations ticket in V7 or file a new ticket in V7 if the change goes through. (Let's add AC to the ticket to remember to do this). But why are we introducing exposing a brand new interface with deprecated options at all? If we remove these options from the interface, we are going to be back at FindOneOptions being the same as FindOptions - is the intent to replace the definition of this interface in V7 with a copy of FindOptions minus these three?
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 expect that once they're removed, we will have:
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.
Yeah, I think if we're doing more than just removing deprecations, we should do it in a separate ticket from the bucket work (to streamline the bucketed option removal).
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.
So a separate ticket to NODE-5545? I had added these removals there but can create a another ticket.
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 don't have a very strong preference as far as using the bucket ticket or filing a separate one if the team feels like it's not necessary, but we do want to capture that this won't be strictly deleting the deprecation lines, because I can see us moving quickly down that list in the bucket and inadvertently ending up back at FindOneOptions = FindOptions