您可以在架构上添加自己的
'remove'Mongoose
中间件,
Person以将该人从引用该人的所有其他文档中删除。在中间件功能中,
this就是
Person要删除的文档。
Person.pre('remove', function(next) { // Remove all the assignment docs that reference the removed person. this.model('Assignment').remove({ person: this._id }, next);});


