Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks

Home Page:https://atmospherejs.com/matb33/collection-hooks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document still inserted/removed if my before-hook returns `false`

SimonSimCity opened this issue · comments

In the documentation and in this change (2c986b3) I saw that it shouldn't be possible to insert a document if the hook for before.insert returns false.

As I've tried this in my project, I was able to still insert or remove documents. Here's a very short sample for a test:

const MyCollection = new Mongo.Collection('my-collection');
MyCollection.before.insert(() => false);
MyCollection.insert({});
// MyCollection.find().count() === 0 --> is false

What works is throwing an error ...

const MyCollection = new Mongo.Collection('my-collection');
MyCollection.before.insert(() => { throw new Meteor.Error(0, 'not-allowed'); });
MyCollection.insert({}); // throws an error

But then not all before-hooks are run, which isn't much of a hassle to me, but maybe to others. What I specially dislike about this way is that I now both have to check for the outcome of the method as well as catching the error - and this on every method where I do something on this collection.

EDIT: I could confirm that updates stop, but not insert or remove calls ...

It seems like something on my setup here is ruining it for some collections ... I'm closing it until further notice.