Skip to content

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

durran
Copy link
Member

@durran durran commented Jul 9, 2025

Description

Changes findOne to set options that will not require a cursor or a killCursors command. Updates find to not leave cursors open on the server when batch size and limit are equal.

What is changing?

  • The find one operation now deprecates options for it specifically which are irrelevant.
  • The find operation now sets batchSize to batchSize + 1 when the limit is equal to it.
  • Syncs CRUD spec tests.
Is there new documentation needed for these changes?

API docs on the findOne options.

What is the motivation for this change?

NODE-6472

Release Highlight

collection.findOne() and collection.find() will no longer potentially leave open cursors on the server

The findOne command will now always set the limit option to 1 and singleBatch to true. The limit, noCursorResponse and batchSize options have also been deprecated, and the command will guarantee no more cursors can be orphaned and no killCursors command will be potentially executed.

find will now set limit to batchSize + 1 when both options were equal, to avoid leaving cursors open.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@durran durran force-pushed the NODE-6472 branch 4 times, most recently from 11b1cf5 to 9fe1c2d Compare July 11, 2025 16:24
@durran durran changed the title feat(NODE-6472): run findOne without cursor feat(NODE-6472): findOne and find no longer keep open cursors Jul 22, 2025
const res = await cursor.next();
await cursor.close();
return res;
const opts = { ...options };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the decision here to do the options changes - creating a new find one operation was much more code and was suspiciously failing 6 tests in load balancer mode. This creating the cursor object works just fine and passes all tests, no killCursors is sent and the cursor on the server side always comes back with id 0.

@durran durran marked this pull request as ready for review July 22, 2025 22:25
@durran durran requested a review from a team as a code owner July 22, 2025 22:25
@baileympearson baileympearson self-assigned this Jul 23, 2025
@baileympearson baileympearson added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants