如何执行此查询?
SELECT * FROM blog
GROUP BY MONTH(createdAt)
我试过的:
Blog.find()
.groupBy({MONTH:'createdAt'})
.exec(function(err,months){
res.view({
layout: 'blogLayout',
archive:months
});
});
给我错误:没有计算就不能分组
Waterline(sails 使用的 ORM)此时仅支持将 groupBy 与 sum()、count() 等结合使用。您可以在此处找到验证这一点的代码行:https ://github.com/balderdashy/sails -mongo/blob/master/lib/query/aggregate.js#L43。