Skip to content

feat(NODE-6290): add sort support to updateOne and replaceOne #4515

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

Merged
merged 2 commits into from
Apr 22, 2025

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Apr 21, 2025

Description

What is changing?

  • Adds support for sort on updateOne and replaceOne operations
    • client bulkWrite and collection bulkWrite versions of these operations support it as well
Is there new documentation needed for these changes?

No

What is the motivation for this change?

The server now supports a sort on these operations, so we do too!

Release Highlight

updateOne and replaceOne now support a sort option

The updateOne and replaceOne operations in each of the ways they can be performed support a sort option starting in MongoDB 8.0. The driver now supports the sort option the same way it does for find or findOneAndModify-style commands:

const sort = { fieldName: -1 };

collection.updateOne({}, {}, { sort });
collection.replaceOne({}, {}, { sort }); 

collection.bulkWrite([ 
  { updateOne: { filter: {}, update: {}, sort } },
  { replaceOne: { filter: {}, replacement: {}, sort } },
]);

client.bulkWrite([
  { name: 'updateOne', namespace: 'db.test', filter: {}, update: {}, sort },
  { name: 'replaceOne', namespace: 'db.test', filter: {}, replacement: {}, sort }
]);

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

@nbbeeken nbbeeken marked this pull request as ready for review April 21, 2025 16:47
@nbbeeken nbbeeken requested a review from a team as a code owner April 21, 2025 16:47
@baileympearson baileympearson self-assigned this Apr 21, 2025
@baileympearson baileympearson added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Apr 21, 2025
Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

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

Just a few minor comments.

@nbbeeken nbbeeken requested a review from baileympearson April 21, 2025 20:42
@nbbeeken nbbeeken force-pushed the NODE-6290-more-sort branch from 7d8d00a to 4f36047 Compare April 22, 2025 14:15
@baileympearson
Copy link
Contributor

Test failures unrelated, they're also failing on main

@baileympearson baileympearson merged commit 28857b7 into main Apr 22, 2025
27 of 30 checks passed
@baileympearson baileympearson deleted the NODE-6290-more-sort branch April 22, 2025 17:46
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.

2 participants