Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sails js - waterline ORM limit or sort after group by?

I am using Waterline ORM for sails.js. limit and sort are not working when you use groupby, but are working fine when you dont do any grouping .

For example

Model.find({
    groupBy:['term'],
    sum:['count'],
    limit:20,
    sort :'count DESC'}).exec(function(error,response){
        if(error) res.json(error);
        res.json(response);
    });
like image 966
sanath_p Avatar asked Jul 02 '14 19:07

sanath_p


1 Answers

Use

Model.find()  
 .groupBy('term') 
 .sum('count')  
 .limit(20)
 .sort({count: 'desc'}) 
 .exec(function (err, data){
 //Your code here..
});
like image 145
Adil Malik Avatar answered Oct 04 '22 04:10

Adil Malik