0

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}})
}

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

{{#each}} only accepts arrays, cursors, or falsey values. You passed: [object Object] showing this error
if we use above findOne command how to iterate through the comments array
Just as you are doing currently because your comments are stored in the questions document in comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.