我正在尝试从我的 mongodb 集合中的“类型”字段中获取唯一值列表。以下示例文档:
{
"_id" : ...,
"type" : "report",
"tasks" : ...
}
{
"_id" : ...,
"type" : "research",
"tasks" : ...
}
{
"_id" : ...,
"type" : "memo",
"tasks" : ...
}
{
"_id" : ...,
"type" : "memo",
"tasks" : ...
}
{
"_id" : ...,
"type" : "report",
"tasks" : ...
}
{
"_id" : ...,
"type" : "report",
"tasks" : ...
}
我正在寻找按频率排序的文档类型字段中的唯一类型,因此:
["report", "memo", "research"]
最好的方法是什么?希望我可以通过使用 mongo 查询而不是下载整个集合来做到这一点......