I would like to keep a count of number of times a post has been viewed. I am using the following code:
Template.post.onCreated(function() {
var id = FlowRouter.getParam("id");
Posts.update(id , {$inc: {viewCount: 1}});
});
I would like to understand what’s wrong with this code. On visiting that particular route, all the other fields in the document get removed and only viewCount and _id remains.
Thanks