Okay I’ve got a bug that just makes no sense at all.
I have a collection hook defined in /server/hooks/products.js
:
///////////////////////////////////////////////////////////////////
// HOOKS //
///////////////////////////////////////////////////////////////////
Products.before.remove(function (userId, doc) {
// Ensure all print list entries that reference this product are removed
PrintLists.update(
{ 'items.product': doc._id },
{ $pull: { items: { product: doc._id } } },
{ multi: true }
);
// Ensures that any recipes that reference this product are removed
Recipes.remove({ productRef: doc._id });
}, { fetchPrevious: false });
which I’ve checked, it fires, and calls PrintLists.update
to remove any items
that reference the product that is about to be removed… BUT it doesn’t get removed.
So I thought I’d just try running the command in the meteor shell
, same thing, returns a 1
but doesn’t remove the document.
I thought I’d try bypassing the Collection2 validations, and the hooks, so I tried a PrintLists.direct.update({...}, {...}, { validate: false })
and still nope, the sub-document in the items
array remains.
So I thought lets see if the mongo shell will remove it:
db.printLists.update({ 'items.product': 'CoMn8WLxCyN9F3Fm5' }, { $pull: { items: { product: 'CoMn8WLxCyN9F3Fm5' } } }, { multi: true })
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
Sure enough the item was then removed, all fine. So why the hell is this not working in Meteor!?