如何返回表中唯一值的计数?这将返回一个唯一ID数组...
req.models.pages.aggregate().distinct("page").get(function (err, page) {...
// returns [ '6', '92', '90', '91', '93', '94', '102' ]
// the unique ids of the individual pages但是,如何返回具有相应计数的对象呢?就像..。
{ '6': 2, '92':7, '90':12, etc...}
// the unique page ids with their associated counts我看到了如何聚合,也看到了如何count(),但我不知道在哪里可以同时使用这两种方法。
发布于 2017-03-16 04:09:54
我能够得到预期的结果使用...
req.models.pages.aggregate(['page']).count().groupBy('page').get(function (err, pages) {...返回了..。
[
{
"page": "6",
"count": 2
},
{
"page": "92",
"count": 7
},
{
"page": "90",
"count": 12
}
]https://stackoverflow.com/questions/42818574
复制相似问题