【发布时间】:2017-12-08 00:33:44
【问题描述】:
我正在寻找构建一个 mongo 查询,该查询将按输入数组中指定的重复关键字的数量对文档进行排序。我的文档如下所示
{
"_id" : 1,
"name" : "invoice",
"rules" : [
{
"_any" : [
"invoice",
"invoices",
"total",
"order",
"bill"
]
}
]
}
{
"_id" : 2,
"name" : "Terms of Service",
"rules" : [
{
"_any" : [
"rule",
"rules",
"terms"
]
}
]
}
那么,假设我的输入数组包含以下关键字
[ 'invoice',
'invoice',
'order',
'bill',
'bill',
'bill',
'bill',
'bill',
'terms'
]
Mongo 应该首先显示 _id: 1 然后是 _id: 2 的结果,因为输入数组包含属于 _id: 1 的关键字的最大数量
提前致谢
【问题讨论】:
标签: arrays mongodb aggregation-framework