As a rule, in such situations, something breaks in the model. In this case, I think this is the idea of a "counting glance." There are many ways to do it right. Incrementing it on rendering is wrong, since you are working with the model in the user interface code (conceptually violated in the implementation).
First save the questions that the user visited somewhere. Why does the {questionsVisited:[]} property not exist for the user?
Use the call to the Meteor.call(...) method to register the view:
Meteor.methods({ viewQuestion: function(questionId) {
So, what about increasing the size of the view in user interfaces? Well, we will not do this. Allow to increase the number of views only when the question changes.
Meteor.autorun(function () { var questionId = Session.get("question_id"); Meteor.call('viewQuestion',questionId,function(e,r) { if (r) console.log("Question " + questionId + " logged an increment."); else console.log("Question " + questionId + " has already been visited by user " + Meteor.userId(); }); });
And get rid of all this supporting question material ...
This is even better than you wanted. Now views are not counted twice for the same user. If this is the desired behavior, remove the questionsVisited logic.
Only change the 'question_id' session variable when you actually change the logical question the user is working with.
source share