Sails.js计数在哪里

我正在计算一个集合的子集,其中的子集由一个属性确定。 代码是:

User.count() .where({attribute:{'<':10}}) .exec(function(err, users){ callback(err, users); }); 

User.count本身将返回总集合计数,但放入任何WHERE子句似乎一贯返回0.是否count方法不支持WHERE子句?

NB我使用Mongodb适配器这个集合和默认情况下。 所有模型都存在“属性”,并填充数字数据(高于和低于10)。

.count()现在也支持标准。 看看文档: https : //github.com/balderdashy/sails-docs/blob/master/reference/waterline/models/count.md

简而言之:

 User.count({name:'Flynn'}).exec(function countCB(err, found){ console.log('There are '+found+' users called "Flynn".'); }); 

您可以在sails v0.10.0-rc4中使用User.countBy(criteria,[callback]) 模型方法countBy