Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
658 stars 90 forks source link

Field names lost in async callback #230

Open micahalcorn opened 7 years ago

micahalcorn commented 7 years ago

I've been using this package for years and love it. I'm upgrading to Meteor 1.5, and I'm running to an issue with asynchronous tasks that are called from update hooks.

fieldNames returns ['foo', 'bar']

MyCollection.after.update(function(userId, doc, fieldNames, modifier, options) {
  console.log(fieldNames);
});

fieldNames returns ['__MONGO_OBJECT_REMOVED__', '__MONGO_OBJECT_REMOVED__']

MyCollection.after.update(function(userId, doc, fieldNames, modifier, options) {
  Meteor.defer(() => {
    console.log(fieldNames);
  });
});

Cloning the argument helps, but it seems inappropriate to reference every variable that will be used in the asynchronous callback. fns returns ['foo', 'bar']

MyCollection.after.update(function(userId, doc, fieldNames, modifier, options) {
  const fns = [...fieldNames];  

  Meteor.defer(() => {
    console.log(fns);
  });
});

Is anyone else experiencing anything like this or have an idea of what might be happening? Google knows nothing about MONGO_OBJECT_REMOVED.

zimme commented 6 years ago

Server side or client side?

micahalcorn commented 6 years ago

@zimme server-side, thx.

zimme commented 6 years ago

I've tried looking around a bit for this and I can't find any reference to MONGO_OBJECT_REMOVED in either this package, meteor or mongodb node driver.

A reproduction repo would probably help to try and track this down.