Groups Collection Records


#1

Hi,

I am been struggling with this for a while.

So I have created a schedule collection of various events. Each have various parameters such as date, time, location, teams playing, etc…

The parameter I am trying to group by is Week No. In sorting it, that was easy since I just had to add the sort on Schedule.find(); however I am trying to group these weeks into sections i.e

Header: Week 1

Individual Boxes: Event A, Event B, Event C

Header: Week 2

Individual Boxes: Event D, Event E, Event F

I have thought about recreating the collection as an array in the helper and return that but I feel like that would be performance consuming. Any thoughts or suggestions on the best way to do this?

Any help would be huge :smile:

Thank you in advance


#2

I would write an aggregate. If you don’t know what that is I would look into the mongodb aggregation pipeline. Which is not natively supported in meteor. Luckily for us, the nice people at meteorhacks have made an aggregate package that I personally use in a production deployment.


#3

I had to keep the db intact. I ended up going with the recreating the collection into an object each time since the volume will be pretty low anyway.

Thank you for your help, I will definitely be using aggregate moving forward.