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 ...
In the documentation and in this change (https://github.com/matb33/meteor-collection-hooks/commit/2c986b3aeae7ad3ce3e146669675fd515db346b9) I saw that it shouldn't be possible to
insert
a document if the hook forbefore.insert
returnsfalse
.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:
What works is throwing 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 ...