Query.prototype.count()

Parameters
  • [filter] «Object» count documents that match this object

  • [callback] «Function» optional params are (error, count)

Returns:
  • «Query» this

Specifies this query as a count query.

This method is deprecated. If you want to count the number of documents in a collection, e.g. count({}), use the estimatedDocumentCount() function instead. Otherwise, use the countDocuments() function instead.

Passing a callback executes the query.

This function triggers the following middleware.

  • count()

Example:

  1. const countQuery = model.where({ 'color': 'black' }).count();
  2. query.count({ color: 'black' }).count(callback)
  3. query.count({ color: 'black' }, callback)
  4. query.where('color', 'black').count(function (err, count) {
  5. if (err) return handleError(err);
  6. console.log('there are %d kittens', count);
  7. })