I need to update that notificationsData reactiveVar as soon as there is a activity in the Notification collection. At the moment if there is a new document added in the collection I have to refresh the page in order to see that new data. What approach should i use to make this instantaneous. Thanks in advance.
It looks like you should be using a publication instead of a meteor method. Meteor methods aren’t reactive, so you’re only fetching the notifications once.
Agree with cereal. If this is truly a collection then you should just subscribe to it. Inside of an autorun you would do your find and it would be re-run any time the collection changes. If instead your notifications are not actually a collection, you would need to do the meteor call at some polling interval. The way you have your code, it would only call it once (well technically it would call it again if the Meteor.userId() ever changed because I believe that is reactive).
This code would be too heavy to run in a polled manner. I think the real problem here is your DB data schema. What you’ve created is typical SQL not mongo. Mongo operates best with de-normalization. Sure you could use aggregate or similar to perform a join of the information, but it would be better to store the job listing columns needed as well as the match data in the main notification table as well.
Perhaps as a quick fix/compromise, you could subscribe to just the notifications and when it changes (autorun) you call your method to gather the data.
Your publish can publish the Notification, JobListings, ResumeDiscussion, and Match cursors, render your notification list, and use findOne for any of the other collections. findOne(_id) is just a hash lookup, so there shouldn’t be any performance implications.
Quick FYI-- passing Meteor.userId() as a method argument is insecure: you cannot rely on clients to behave nicely. IOW a client could put a different userId in there. Correct is to rely on the server to provide the ID of the current client. See https://docs.meteor.com/api/methods.html#DDPCommon-MethodInvocation-userId