How do I perform this query using sailsjs ORM (waterline)

穿精又带淫゛_ 提交于 2019-12-10 19:57:05

问题


How do I perform this query?

SELECT * FROM blog
GROUP BY MONTH(createdAt)

What I've tried:

Blog.find()
.groupBy({MONTH:'createdAt'})
.exec(function(err,months){

        res.view({
          layout: 'blogLayout',
          archive:months
        });


 });

Gives me Error: Cannot groupBy without a calculation


回答1:


Waterline (the ORM used by sails) at this point only supports using groupBy in combination with sum(), count() etc. You can find the line of code that verifies this here: https://github.com/balderdashy/sails-mongo/blob/master/lib/query/aggregate.js#L43.



来源:https://stackoverflow.com/questions/20254910/how-do-i-perform-this-query-using-sailsjs-orm-waterline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!