Sasikanth
Sasikanth

Reputation: 3043

meteor iterate through array

here is my collection

Ques_Coll.insert({question: quest,owner:u_name,comments:[]});

After user enters comment, collection will be updated like this

Ques_Coll.update({_id:this._id},{$push:{comments:{uname:"xxx",cmt_text:"xxx"}}});

Until this working fine

Now, i want to iterate through all the comments and want to display them

how to do it?

this is how i tried and not working

{{#each all_comments.comments}}
<li>{{uname}}</li>
<li>{{cmt_text}}</li>
{{/each}}

this is my template //i think my problem lies in this returning value

all_comments:function()
{
    return Ques_Coll.find( {_id:this._id},{fields: {'comments': 1}})
}

Upvotes: 0

Views: 1265

Answers (1)

Tarang
Tarang

Reputation: 75975

Use findOne instead:

Ques_Coll.findOne( {_id:this._id},{fields: {'comments': 1}})

You use find when you're searching for more than one question to match the criteria. But since you're looking for one (the one with the comments), you use findOne instead.

Upvotes: 2

Related Questions