feat(db-mongodb): allow user to have custom options while using `payload.update` operation
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
- [x] New feature (non-breaking change which adds functionality)
Checklist:
- [x] I have read and understand the CONTRIBUTING.md document in this repository.
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] Existing test suite passes locally with my changes
- [x] I have made corresponding changes to the documentation
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?
I'll resolve all the conflicts over weekends. Thank you for getting back to my PR 😅
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?