javascriptnode.jsmeteormeteor-collection-hooks

Howto interrupt meteor collections insert in the before hook?


How can i interrupt an insert by checking some condition in the before hook?

Collection.before.insert((userId, doc) => {
  if(doc.property != valid){
    // interrupt insert here
  }
});

i tried throw new Meteor.Error('Insert Error','Not Allowed...') but this didn't interrupt the process of the insert.

Another possibility would be, to go in the after hook and delete the inserted document.... but this is an ugly solution.


Solution

  • You can prevent the insertion by returning false.