Meteor-CollectionFS
Meteor-CollectionFS copied to clipboard
Event Listeners for all FS collection
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
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
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
apparently there is something going on around https://github.com/CollectionFS/Meteor-CollectionFS/blob/master/packages/collection/common.js#L65