First of all, this code works but I just want to make sure it is correct. Is this the proper way of removing referenced data when using mongoose?:
router.delete("/clients/:client_id/domains/:domain_id", function(req,res) {
Client.findById(req.params.client_id).populate("domains").exec(function(err, client) {
Domain.remove({_id: req.params.domain_id}, function(err,dom) {
client.domains.remove({_id: req.params.domain_id});
client.save(function(err) {
console.log(err);
});
});
});
res.redirect("/");
});
Can I somehow automatically remove it from referenced and populated domains
array or do I have to first remove it by calling remove
on a model and then pulling it from array like in the example above? Thanks for your help in advance.