Getting duplicates from collection

Hey,

I have a collection called Collection with multiple items, lets say:

{ "Country" : "United States", "State" : "Florida" }
{ "Country" : "United States", "State" : "California" }
{ "Country" : "United States", "State" : "New York" }

I want to output United States once and have underneath it, all the different states that are associated to “United States”. How would I go about doing this?

Use aggregation and group them by Country… This is the package https://atmospherejs.com/jcbernack/reactive-aggregate and if you fins some errors during aggregation then add this package as well https://atmospherejs.com/meteorhacks/aggregate

Thanks for your response! I actually have other values in each collection item as well, other than country and state. Could you explain how the aggregation package can be used in this situation?

I’m looking to create a helper function on the client side that will return the main country and then each state associated with it.

You need to know the mongodb aggregation and grouping. The package will just help you on how to code it in meteor…

Try to look at this example: http://stackoverflow.com/questions/22932364/mongodb-group-values-by-multiple-fields

Ah, thank you. I will go over that!