Automatically remove referencing objects on deletion in MongoDB
You can add your own 'remove'
Mongoose middleware on the Person
schema to remove that person from all other documents that reference it. In your middleware function, this
is the Person
document that's being removed.
Person.pre('remove', function(next) {
// Remove all the assignment docs that reference the removed person.
this.model('Assignment').remove({ person: this._id }, next);
});
If by "simple" you mean "built-in", then no. MongoDB is not a relational database after all. You need to implement your own cleaning mechanism.