Preview:
RoleModel.pre('deleteOne', async function(next) {

    try {
        let deletedItemId = (this._conditions && this._conditions._id) ? this._conditions._id : null;
        if(deletedItemId){
            await UserModel.deleteMany({ 'role': deletedItemId });
        }
        next();
    } catch (e) {
        console.log(e);
    }
});
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter