docs/reference/waterline/models/count.md
.count()Get the total number of records matching the specified criteria.
var numRecords = await Model.count(criteria);
| # | Argument | Type | Details |
|---|---|---|---|
| 1 | criteria | ((dictionary?)) | The Waterline criteria to use for matching records in the database. Note that count queries do not support pagination using skip and limit or projections using select. |
| Type | Description |
|---|---|
| ((number)) | The number of records from your database that match the given criteria. |
| Name | Type | When? |
|---|---|---|
| UsageError | ((Error)) | Thrown if something invalid was passed in. |
| AdapterError | ((Error)) | Thrown if something went wrong in the database adapter. |
| Error | ((Error)) | Thrown if anything else unexpected happens. |
See Concepts > Models and ORM > Errors for examples of negotiating errors in Sails and Waterline.
var total = await User.count({name:'Flynn'});
sails.log(`There ${total===1?'is':'are'} ${total} user${total===1?'':'s'} named "Flynn".`);
<docmeta name="displayName" value=".count()"> <docmeta name="pageType" value="method">
- This method can be used with
await, promise chaining, or traditional Node callbacks.