<templatename="commentSubmit"><formname="comment"class="comment-form"><divclass="control-group"><divclass="controls"><labelfor="body">Comment on this post</label><textareaname="body"></textarea></div></div><divclass="control-group"><divclass="controls"><buttontype="submit"class="btn">Add Comment</button></div></div></form></template>

Comments=newMeteor.Collection('comments');Meteor.methods({comment:function(commentAttributes){varuser=Meteor.user();varpost=Posts.findOne(commentAttributes.postId);// ensure the user is logged inif(!user)thrownewMeteor.Error(401,"You need to login to make comments");if(!commentAttributes.body)thrownewMeteor.Error(422,'Please write some content');if(!post)thrownewMeteor.Error(422,'You must comment on a post');comment=_.extend(_.pick(commentAttributes,'postId','body'),{userId:user._id,author:user.username,submitted:newDate().getTime()});returnComments.insert(comment);}});

// pick out the whitelisted keysvarpost=_.extend(_.pick(postAttributes,'url','title','message'),{userId:user._id,author:user.username,submitted:newDate().getTime(),commentsCount:0});varpostId=Posts.insert(post);

collections/posts.js

////

// update the post with the number of commentsPosts.update(comment.postId,{$inc:{commentsCount:1}});returnComments.insert(comment);