Here\'s my MongoDB collection:
{
\"_id\" : ObjectId(\"515d8f53175b8ecb053425c2\"),
\"category\" : \"Batteries\",
\"products\" : [
{
After few more tries, I had solved this. Here's the commands:
db.xyz.aggregate( {$project: {a: '$products.item'}},
{$unwind: '$a'},
{$unwind: '$a'},
{$group: {_id: 'a', items: {$addToSet: '$a'}}});
and
db.xyz.aggregate( {$project: {category: 1, a: '$products.item'}},
{$unwind: '$a'},
{$unwind: '$a'},
{$group: {_id: '$category', items: {$addToSet: '$a'}}});