1

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.

Community
  • 1
  • 1
sanjeev mk
  • 4,276
  • 6
  • 44
  • 69
  • Use the [**meteorhacks:aggregate**](https://atmospherejs.com/meteorhacks/aggregate) package that adds proper aggregation support for Meteor. – chridam Sep 20 '15 at 15:59

1 Answers1

1
  1. You can do:

{{#each this.array}} {{name}} {{/each}

tip: you can also do collection.find().fetch() it will return all matching documents as an Array. http://docs.meteor.com/#/full/fetch

  1. Aggregate isn't supported yet in meteor you can add by doing meteor add meteorhacks:aggregate