I have tries to delete referenced documents in mongoDb when Company is deleting.But after i execute following it only deletes the Company and not executing middle ware body
const removedCompany = await CompanyModel.findOne({ _id: id }).remove();
inside schema file
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();
});
lambda function implements "this" as lexical this so it will not work use old style
https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20%26%20beyond/ch2.md#not-just-shorter-syntax-but-this