Say I have a MongoDB collection with documents like—
{
"name": "Hawaiian",
"toppings": ['cheese', 'ham', 'pineapple'],
}
How could I get a list of all the collection’s toppings?
I assume I’d have to use MapReduce or the new aggregation framework (ideally MapReduce as I can’t use the new aggregation framework), but I’m not sure how to do it.
Thanks!
Edit: And, is there a way to count the number of distinct toppings at the database level?
MongoDB supports DISTINCT aggregation. This should do the trick.