I am using MongoDB. and I have multiple fields in documents of one collection, which are color, style, keywords, shape, etc. and all data type is an Array. I want all the unique values of color, style, shape, keywords, etc. from all the documents.
Sample document as pr below
"_id": "5de63ae0d88ea145cc7accb5",
"id": "28011",
"name": "BID 2",
"slug": "bid-2",
"description": "<p>Decorative details of graphic foliage interpreted in the latest colours such as black, pink, green and turquoise. The soft texture of the ceramic envelops with warmth even the coldest dish.</p>\r\n\r\n<ul>\r\n\t<li>Dishwasher and microwave safe</li>",
"price": "0.00",
"keywords": [
"Kitchen",
"cook",
"cooking",
"kitchens",
"pantry",
"kitchen room",
"room",
"cookhouse",
"cookery",
"cuisine",
"cook room",
"food",
"Crockery",
"dishware",
"dishes",
"plates",
"platters",
"stoneware",
"bone china",
"porcelain",
"earthenware",
"ironstone",
"plate",
"dish",
"small dish",
"fruit dish",
"fruit plate",
"",
"dessert plate"
],
"Country": [
"Italy"
],
"Shape": [
"Round"
],
"Brand": [
"Bitossi Home"
],
"Materials": [
"Ironstone"
],
"Usage": [
"Fruit Plate"
],
"Color": [
"Pink"
]
}
}
I tried with $groupby. but it's giving me unique arrays in different arrays. I want result like below
{'color' : ['blue', 'red', 'green', 'white', 'gold'],
'shape' : ['round', 'square'],
'style' : [],
'keywords' : ['room', 'kitchen']}