I'm trying to count a subset of a collection, where the subset determined by an attribute. The code is:
User.count()
.where({attribute:{'<':10}})
.exec(function(err, users){
callback(err, users);
});
User.count
by itself will return the total collection count, but putting in any WHERE clauses seems to consistently return 0. Does the count
method not support WHERE clauses?
NB I'm using the Mongodb adapter both for this collection and by default. The 'attribute' exists on all models and is populated with numerical data (above and below 10).
.count() now supports criteria, too. Take a look at the docs: https://github.com/balderdashy/sails-docs/blob/master/reference/waterline/models/count.md
In a nutshell:
User.count({name:'Flynn'}).exec(function countCB(err, found){
console.log('There are '+found+' users called "Flynn".');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With