mongoose-sequence
mongoose-sequence copied to clipboard
Query middleware support
Update counters on findOneAndUpdate
and update
Based on the work by @linusbrolin.
- [x] Add tests
- [x] Rebase on latest develop
- [ ] Add tests for
multi
option (on update) - [ ] Add same functionality for referenced fileds
- Try to avoid a query to know if the upsert inserted a document
I found another bug, when using scoped counter (I never tested that before, my bad), where the reference value(s) would be null. I've fixed it in my fork (same branch as before), so you should probably update this PR to the latest code from my branch.
I'll do, and I will add the related test
Coverage remained the same at 100.0% when pulling 12939b881f0d8be12e8769c6d477eda4be69beb4 on query-middleware-support into 727be42dd65110735017f84a870a8e933d7683ae on develop.
Coverage remained the same at 100.0% when pulling b50319d3722913d5f3e3d09d654a807b481c0e0d on query-middleware-support into 16e3d01e057bd847a12dfeed5e9e86ac808aff53 on develop.
Coverage remained the same at 100.0% when pulling 96d6639c28fb8f8b7c53ef32c87d793a8fadaada on query-middleware-support into 65ec0a147b3adc148556c6752aca67ef3e20ab79 on develop.
Coverage remained the same at 100.0% when pulling 98b11b87547f0d267259f6e40aceb1e9b97f54ac on query-middleware-support into 65ec0a147b3adc148556c6752aca67ef3e20ab79 on develop.
any update ? It's still not working for findOneAndUpdate
@ramiel I have now rebased my branch on the latest code from your master branch, and updated the code accordingly. https://github.com/linusbrolin/mongoose-sequence/tree/query-middleware-support It should work with the parallel_hooks option, but I have not added any tests for it due to limited amount of time. I am however using it in a work project and it is working there.
If you could add the needed tests then I would very much appreciate it, otherwise I'll see if I can find time to do that myself.
For now I have added a check for the multi
option on update
, and exit the hook if true.
And I have not added support for updateMany
either, yet, due to limited time.
But I honestly think we should at the very least get support for upserting single documents released now, as it's been 5 years since my original PR!
Or if someone wants to help adding support for updateMany
and update
with multi: true
?
Let me know what you think.