Getting duplicates from collection



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 and if you fins some errors during aggregation then add this package as well


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:


Ah, thank you. I will go over that!