I am having trouble understanding how to use aggregate pipelines in Mongo.
Given the list following documents:
db.dishes.insertMany([
{_id: "Vanilla Sundae", keywords: ["vanilla", "ice cream", "desert"] },
{_id: "Vanilla Cake", keywords: ["vanilla", "cake", "baking", "desert"] },
{_id: "Chocolate Cake", keywords: ["chocolate", "cake", "baking", "desert"] }
])
How do I create an aggregate that would return a list of distinct keywords and counts of docs by keywords:
[
{"_id": "vanilla", "count": 2},
{"_id": "ice cream", "count": 1},
{"_id": "desert", "count": 3},
{"_id": "baking", "count": 2},
{"_id": "cake", "count": 2},
{"_id": "chocolate", "count": 1}
]