View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

.count( [criteria, ] callback )

Purpose

Returns the number of records in your database that meet the given search criteria.

Overview

Parameters

# Description Accepted Data Types Required ?
1 Find Criteria {},[{}], string, int No
2 Callback function No

Callback Parameters

# Description Possible Data Types
1 Error Error
2 Number of Records int

Example Usage

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

  // There are 1 users called 'Flynn'
  // Don't forget to handle your errors
});

Notes

Any string arguments passed must be the ID of the record.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book