Skip to content

feat(db-mongodb): allow user to have custom options while using payload.update operation #4369

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 2 commits into
base: main
Choose a base branch
from

Conversation

WilsonLe
Copy link
Contributor

@WilsonLe WilsonLe commented Dec 4, 2023

Allow user to provide custom options when using update operations

This PR allows user to provide custom options when using payload.update(...). The custom options is optional and therefore won't break existing code. The custom options allow user to further leverage database ORMs and ODMs specific update options down the line. This PR specifically changes mongoose database adapter such that user can leverage the upsert option when using findOneAndUpdate operation.

Example usage:

await req.payload.update({
    collection: "users",
    data: { ... },
    options: { upsert: true } // new changes
})

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have read and understand the CONTRIBUTING.md document in this repository.
  • I have added tests that prove my fix is effective or that my feature works
  • Existing test suite passes locally with my changes
  • I have made corresponding changes to the documentation

@DanRibbens
Copy link
Contributor

This is a good feature idea. I added similar for v3 but only at the db adapter method level. It would really help us if you wanted to make the same PR to main so it can get into v3 going foward.

What do you think @WilsonLe?

@DanRibbens DanRibbens added the keep Prevents from being marked stale or auto-closed. label Dec 6, 2024
@WilsonLe WilsonLe changed the base branch from 2.x to main December 6, 2024 14:44
@WilsonLe WilsonLe changed the title Allow user to have custom options while using payload.update operation feat(db): Allow user to have custom options while using payload.update operation Dec 6, 2024
@WilsonLe WilsonLe changed the title feat(db): Allow user to have custom options while using payload.update operation feat(db-mongodb): Allow user to have custom options while using payload.update operation Dec 6, 2024
@WilsonLe WilsonLe changed the title feat(db-mongodb): Allow user to have custom options while using payload.update operation feat(db-mongodb): allow user to have custom options while using payload.update operation Dec 6, 2024
@WilsonLe
Copy link
Contributor Author

WilsonLe commented Dec 6, 2024

I'll resolve all the conflicts over weekends. Thank you for getting back to my PR 😅

@WilsonLe
Copy link
Contributor Author

After merging with main, it seems like this has been implemented. However, why didn't we accept the options parameter in payload.update and forward it to payload.db.updateOne? Or was the options parameter is already forwarded and I just didn't see it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Prevents from being marked stale or auto-closed. stale v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants