Company collection:
{
"_id": {
"$oid": "594196a685d5c72f00517f64"
},
"name": "company",
"reports": [
{
"$oid": "5942afb5314f0235d9a3a302"
},
{
"$oid": "5942b1641b10b236075bcd89"
}
],
}
I understand I have to use update $pull to remove an element from reports.
How would create the query to achieve this?
I have this so far,
var Company = require('../models/company');
Company.update(
{ _id: company},
{ $pull: {'reports': report._id} }
)
Is there a way to remove reports from this company automatically if I delete a report?
For example, instead of having to use update()
on Company after a report is deleted, it would be nice if I can just do remove()
on a report and Company should know it was deleted. (I come from a rails background so this is annoying)