Posts view count in meteor

I would like to keep a count of number of times a post has been viewed. I am using the following code: {
  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.


use $set: , otherwise you need to provide whole new document by which it should be replaced.
What you are actually doing atm :smiley:

Try this, this code works for me locally:

Posts.update(id, {
  $inc: { viewCount: 1 }