SoftwareBrothers / adminjs-mongoose

Mongoose adapter for AdminJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update problem for mongoose pre save hooks

berkkarahan opened this issue · comments

Hey,
When updating a resource from admin panel, schema pre-hooks doesn't run.
However, when creating it, it runs perfectly.

This is the message at terminal in my express application,

(node:50219) DeprecationWarning: Mongoose: findOneAndUpdate() and findOneAndDelete() without the useFindAndModify option set to false are deprecated. See: https://mongoosejs.com/docs/deprecations.html#-findandmodify-

it is actually a mongoose error , they are changing few libraries.
https://mongoosejs.com/docs/deprecations.html#findandmodify

add this part below the mongoose connections

//for  eprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify`
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);
mongoose.set('useUnifiedTopology', true);

Hello @berkkarahan & @Swarag-N,
I am using admin-bro for one of my projects. The pre-hook/ post-hook isn't working for me. If I am making an API call, It triggers pre/post-hook, but it didn't work when clicking on save in admin-bro. Are you facing this problem @berkkarahan?