Howto interrupt meteor collections insert in the before hook?

120 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

You can prevent the insertion by returning false.