Comment section of a web app not woking


I am new to meteor and In my web app (Meteor 1.2.1) the users can make posts and under the posts can make comments. I am pushing the comments into the comment array in the post collection but the code updates the array only when me as the owner of post i make a comment in my own post. If i try to make a comment in someone’s else post the array updates with an empty string. The second is that i want to update the commentUsers array which holds the user who made a comment. This works but it updates the array with all the information of the user, i just want the username. And the third is i don’t know how to access the comments array of a certain post and display the results on the screen.
Here is the code:


  'submit .comment-form': function(event){
    var content = document.getElementsByClassName('form-comment')[0].value;
    var user = Meteor.user();
    var username = user.username;
    console.log(username);'comment', this, content, user);



Post = new Mongo.Collection('post');

  addPost: function(content){
      throw new Meteor.Error('not-authorized', 'you are not signed');
    var username = Meteor.user().username;

      content: content,
      created: new Date(),
      username: username,
      comments: [],
      commentUsers: []
  follow: function(post){
    var user = Meteor.user();

      throw new Meteor.Error('not-authorized', 'you are not signed');

    if(user.username != post.username && user.profile.follow.indexOf(post.username) == -1) {
      //if everything is correct then we will update the current user and will push
      //the to the array the new user name which we are taking his information from the post
      Meteor.users.update({_id: user._id},
        {$push: {'profile.follow': post.username}
  comment: function(post, content, username) {
    //var user = Meteor.user();

    throw new Meteor.Error('not-authorized', 'you are not signed in');


  Post.update({_id: post._id},
    {$push: {'comments': content, 'commentUsers': username }}
    //{$push: {'commentUsers': username }}



  comments: function(postId){
    var comments = Post.findOne({postId: postId})._id;

    return  comments.comments;


<template name="commentsList">
    {{#each comment in comments}}
    <li>{{comments _id}}</li>


You might try these packages.


This should just be

{{#each comments}}

Your syntax for {{#each}} was wrong.

This will work if a content is an object that looks like {_id: "blah", message: "message"}.


Actually it was also a correct syntax but needed to reference the new comment var inside the “#each…in” block


Ah, I wasn’t sure if that existed in Meteor 1.2.1 :slight_smile: Good catch!


Thanks for the answers. I uploaded an image of my browser console to show you what i get when i post a comment. The comment array of the last post is filled with comments while the rest have empty strings.