Helper inserting data duplicates into a collection every time I refresh the page?

I’m having a problem trying to implement notifications in meteor. I have this code inside a helper. It works correctly and gives the current user the right notifications for what they have subscribed to. However whenever I refresh the page the same notification is inserted twice into the notifications collection showing the user duplicates of the same notification in the ui. Anyone one know how to fix this?


  notifications : function(){


    var currentUserID = Meteor.userId();
    var usersEventIds =  Subscriptions.find({userID: currentUserID}, {"eventID": 1});
    var userCategorys = Subscriptions.find({userID: currentUserID}, {"category": 1});
    var arrayEvents = [];
    var arrayCategory =[];

    usersEventIds.forEach(function (collection) {

  userCategorys.forEach(function (collection) {

//All the status's the user should be notified for based on what eventID and categorys he/she is subscribed to.
  var userNotifications = Status.find( { $and: [ { eventID: { $in: arrayEvents  } } , { category: { $in: arrayCategory } } ] } );

//Putting all these status's into a notifications collection.

  userNotifications.forEach(function (collection) {

    var eventID = collection.eventID;
    var category = collection.category;
    var eventName = collection.currentEventName;'insertNotificationsData', eventID,category,eventName,currentUserID);

return Notifications.find({currentUserID:currentUserID});



I would not subscribe to collections in a helper. They get called several times in the lifecycle of a template. You should check out the Meteor Guide