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:
const countQuery = model.where({ 'color': 'black' }).count();
query.count({ color: 'black' }).count(callback)
query.count({ color: 'black' }, callback)
query.where('color', 'black').count(function (err, count) {
if (err) return handleError(err);
console.log('there are %d kittens', count);
})
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .