Collection-Hook run all of "before.insert(), before.update()" at the same time when I "insert" data in autoform?

I use collecion2, simple schema, auto form and collection-hook.

// Server
Customer.before.insert(function (userId, doc) {
    console.log('before insert');
Customer.before.update(function (userId, doc, fieldNames, modifier, options) {
    console.log('before update');

Collection-Hook run all of before.insert(), before.update() at the same time when I insert data in autoform.
Please help me.

and what exactly is the problem here?

just log what values are in these additional properties and formulate what you want to do in that hook behind IF statement which describe situation when to react that way.

When I click the submit on insert form of autoform, the berfor.insert() and before.update() run both at the same time.

// Result on cmd
before insert
before update

I think that It should be run on before.insert() only.

Oh I think that have problem with jeanfredrik:denormalize package.
I will try remove …

I think this is a design bug with jeanfredrik:denormalize where he should have been using direct inserts/updates to bypass collection hooks that are already defined and purposed for other things.

That being said, you should always design your own hooks to check for arguments of the insert/update and run if there actually is need to run.

I want to use this `denormalizè, but now it have problem with my own hook.
What I should do?

You have two options:

  1. post an issue on the github issue tracker for denormalize
  2. check the modifier within the update hook and if the modifier does not contain the keys that you want to run updates after, do nothing.