Conversation
… and add findOneAndReplace support Fix #75
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR addresses a critical issue where query transforms run before middleware, which has been causing the plugin to misbehave. The changes include:
- Adding support for the findOneAndReplace operation in tests.
- Updating the middleware to unshift the transform across multiple query operations (including findOneAndReplace) so it executes prior to user-supplied transforms.
- Removing redundant post hooks in favor of the new pre hook approach.
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/index.test.js | Added a new test case for the findOneAndReplace operation. |
| index.js | Modified middleware to switch to an unshifted pre hook for multiple query types. |
Files not reviewed (1)
- package.json: Language not supported
Comments suppressed due to low confidence (1)
test/index.test.js:100
- [nitpick] It may be beneficial to extend the test case for findOneAndReplace by considering edge cases, such as scenarios where an empty dataset is returned, to ensure the transform behavior remains consistent.
return model.findOneAndReplace({ _id: docId }, { ...baseObj }).lean(leanOptions).exec();
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…-virtuals into vkarpov15/gh-75
hasezoey
approved these changes
May 2, 2025
Member
hasezoey
left a comment
There was a problem hiding this comment.
LGTM, though i have not much experience with this plugin.
Co-authored-by: hasezoey <hasezoey@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #75
Summary
#75 points out a significant issue in this plugin's functionality: Query
transform()s run before middleware, so transform that changes the query shape causes this plugin to break. Fix the issue by making this pluginunshift()a transform to the front of the transforms array inpre(), which will ensure this plugin's transform will run before any user-specified transforms.This change will require a 2.0.0 release because it may break some existing code.
@hasezoey can you please take a look at this one?
Examples