我正在尝试计算集合的子集,其中子集由属性确定.代码是:
User.count()
.where({attribute:{'<':10}})
.exec(function(err, users){
callback(err, users);
});
Run Code Online (Sandbox Code Playgroud)
User.count本身将返回总集合数,但是放入任何WHERE子句似乎始终返回0.该count方法是否不支持WHERE子句?
注意我在这个集合中使用Mongodb适配器,默认情况下.'属性'存在于所有模型上,并填充了数字数据(高于和低于10).
Wes*_*ijk 16
.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".');
});
Run Code Online (Sandbox Code Playgroud)