arashsheyda / nuxt-mongoose

A Nuxt module for simplifying the use of Mongoose in your project.
https://docs.arashsheyda.me/nuxt-mongoose
69 stars 11 forks source link

Hooks not working #13

Closed autorunman22 closed 11 months ago

autorunman22 commented 11 months ago
hooks(schema) {
        schema.pre('remove', async (this, next) => {
            console.log(`lets remove`);
            try {
                await PosSchema.deleteMany({ branch: this._id} )
                next()
            } catch (error) {
                next(error)
            }
        })
    },

The Pos record is not being deleted and there was never a log in console.

arashsheyda commented 11 months ago

there is no remove in pre. you can try using deleteOne or deleteMany

you can read about this here

@autorunman22 let me know if there is anything else that I can help with. thank you

autorunman22 commented 11 months ago

solved using findOneAndDelete instead