I have a my collection as below:
id: 'some_id'
items: [ {name:x}, {name:y} ]
When I do collection_object.find({id:'some_id'},{items:1,_id:0})
, it returns an object and not the actual array. Then I followed the answer here , and used the aggregate
function in my Meteor helper, instead of find. The new call being:
collection_object.aggregate({$match:{id:'mseb'}}, {$unwind:'$items'} )
This raises the error that aggregate
is undefined.
Two questions:
1. If the find
call returns an object containing the array, how do I access individual elements of the array in the template. Using {{this.items}}
shows an array of again, "objects", and {{this.items.name}}
is undefined.
2. If not 1, then how to make aggregate
work with meteor.
Update: I followed the meteorhacks:aggregate approach, but that too gave the same result. The answer below worked for me.