【发布时间】:2019-12-03 06:58:35
【问题描述】:
我正在使用 MongoDB。我在一个集合的文档中有多个字段,它们是颜色、样式、关键字、形状等,所有数据类型都是数组。我想要所有文档中颜色、样式、形状、关键字等的所有唯一值。
示例文档如下 pr
"_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"
]
}
}
我尝试使用 $groupby。但它给了我不同数组中的独特数组。我想要如下结果
{'color' : ['blue', 'red', 'green', 'white', 'gold'],
'shape' : ['round', 'square'],
'style' : [],
'keywords' : ['room', 'kitchen']}
【问题讨论】:
-
用示例数据提出问题,并提供您迄今为止尝试过的内容
-
@sathish 请使用示例文档和响应示例检查修改后的问题。
标签: mongodb filter distinct unique-values