Sails.js counts where

I am trying to count a subset of a collection where a subset is defined by an attribute. The code:

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

User.countIt will itself return a total collection counter, but the inclusion of any WHERE clauses seems to consistently return 0. Does the method support countWHERE clauses?

NB I use the Mongodb adapter for both this collection and the default. An “attribute” exists for all models and is populated with numerical data (above and below 10).

+4
source share
2 answers

.count () now also supports criteria. Take a look at the docs: 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".');
});
+16

User.countBy(, [ ]) v0.10.0-rc4:) countBy

0

Source: https://habr.com/ru/post/1532747/


All Articles