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.

1
  • Use the meteorhacks:aggregate package that adds proper aggregation support for Meteor. Commented Sep 20, 2015 at 15:59

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

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.