collection.count
Returns the count of documents that would match a find()
query. The collection.count()
method does not perform the find()
operation but instead counts and returns the number of results that match a query. The method points to collection.countDocuments()
in the mongo driver.
Arguments
query
(String|ObjectId|Object): The query for the count.[
options
] (object)[
callback
] (function)
Returns
A promise
Example
users.count({name: 'foo'})
users.count('id') // a bit useless but consistent with the rest of the API
users.count()
Getting an estimated count
If you need to get a fast order of magnitude of the count of all documents in your collection, you can use the estimate
option.
⚠️ The
query
argument will be ignored.
users.count({}, { estimate: true })