This is my mongodb document
{
"_id" : "a3s6HzG9swNB3bQ78",
"comments" : [
{
"cmt_text" : "opp",
"vCount" : 2,
},
{
"cmt_text" : "o2",
"vCount" : 5,
},
{
"cmt_text" : "o3",
"vCount" : 3,
}
],
"question" : "test ques 3"
}
i want to sort the result using the vCount
field how to achieve this
i tried the following but seems to be not working
Coll.findOne( {_id:this._id},{sort:{ "comments.vCount" : 1 }});
Coll.findOne( {_id:this._id},{sort:{ "comments.$.vCount" : 1 }});
anyone have idea about this???
EDIT
we are returning only one document and i want to display that document comment array values according to the vCount
. my code
{{#each all_comments.comments}}
<br>{{cmt_text}}</p>
{{/each}}
i want to display like below
o2
o3
opp
EDIT
this is working fine in shell
db.testCol.aggregate([
{ $unwind: "$comments" },
{ $group: { _id: { id:"$_id", vcount:"$comments.vCount"} } },
{ $sort: { "_id.vcount":1 }}
])
why is it not working in my meteor app it says
error:object has no method aggregate