Meteor-CollectionFS icon indicating copy to clipboard operation
Meteor-CollectionFS copied to clipboard

Event Listeners for all FS collection

Open Jaetoh opened this issue 8 years ago • 3 comments

Hi ! I use two FS collections. I insert the fileObj of the first collection once it is stored into the collection 2. But when once the fileObj is stored into the second collection, Collection1.on('stored') is called again !! Whereas it is two difference collections, i don't understand what's wrong.


Collection1.on('stored', Meteor.bindEnvironment( function (fileObj,store) {

                                              Meteor.call('insert_in_collection2',fileObj._id);

}));

Thanks in advance for your reply

Jaetoh avatar May 04 '16 07:05 Jaetoh

It is like the event listener Collection1.on('stored' is called for all the FS store of the app. To avoid this error i added

Collection1.on('stored', Meteor.bindEnvironment( function (fileObj,store) {
 if ( store == "name_of_the_store_desired ) {
                                              Meteor.call('insert_in_collection2',fileObj._id);
}
}));

But i don't really want to handle the error like that, if someone has an other idea

Jaetoh avatar May 04 '16 07:05 Jaetoh

Any update for this ? getting the same error... it's pretty annoying


Edit : I noticed, that even if an error shows up, the methods is still launch.

So you can add

if (store == fileObj.collectionName) { // do my things }

no more error, and you don't have to do the hard comparison for the collection name

rolljee avatar Oct 14 '16 10:10 rolljee

apparently there is something going on around https://github.com/CollectionFS/Meteor-CollectionFS/blob/master/packages/collection/common.js#L65

fadomire avatar Jun 28 '17 18:06 fadomire