pre remove middleware no longer called
See original GitHub issueDo you want to request a feature or report a bug? Undocumented Behaviour, Possible Bug?
What is the current behavior? Using following code from previous version with the latest version:
let user = await Models.user.findById(req.params.id)
...
await user.remove()
When using Object.remove() it also calls schema.pre('remove', function...
. But now in the latest version when using remove it prints: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
. But with that the pre(‘remove’) no longer gets called. I tried the deleteOne and the oder findByIdAndDelete() calls but the pre(‘remove’) gets never called.
What is the expected behavior? I can not find in the docs if the pre(‘remove’) still exists and if what action actually invoked it.
Please mention your node.js, mongoose and MongoDB version. node v9.5.0 mongoose 5.2.9 mongodb 3.6
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
document.remove() has been updated in the master branch to call
collection.deleteOne
instead ofcollection.remove()
. The hooks will still be called and no further deprecation warnings will come from calling document.remove(). The next release of mongoose will contain the fix for this 👍Awesome! Thank you very much for your assistance! Appreciate it.