我試圖刪除MongoDB中引用的文件時,公司是deleting.But後,我執行以下只刪除了公司,而不是執行中間件體貓鼬預功能不會對中間件工作刪除
const removedCompany = await CompanyModel.findOne({ _id: id }).remove();
架構文件內
CompanySchema.pre('remove', (next) => {
// 'this' is the company being removed. Provide callbacks here if you want
// to be notified of the calls' result.
UserCompany.remove({ companyId: this._id }).exec();
next();
});