【发布时间】:2020-01-26 20:45:08
【问题描述】:
这是我的文档格式
[
{
"name" : "test1",
"other_name" : "TEST1_1",
"values" : ["11", "12", "13", "14"]
},
{
"name" : "test2",
"other_name" : "TEST2_1",
"values" : ["21", "22", "23", "24"]
},
{
"name" : "test3",
"other_name" : "TEST3_1",
"values" : ["11", "32", "13", "14"]
}
]
我想要的输出为:
["11", "12", "13", "14", "21", "22", "23", "24", "32"]
我应该也可以对它们进行过滤(仅过滤值数组)、orderby(仅按值数组排序)。
你能帮我解决这个问题吗?
我试过这个:
db.collection.distinct('values', { "values" : /32/ }).sort();
但这是返回所有值,如 "11", "32", "13", "14" 我只想要特定值,你能帮忙吗?
【问题讨论】:
-
您想要的 o/p 已合并来自所有三个文档的唯一值,您所说的“我只想要特定值”是什么意思??
标签: python mongodb mongodb-query aggregation-framework pymongo