MongoDB count() returns the number of results in a specified collection or number of documents that match in a find() query.
Syntax of count()
Here, count returns only number of results that match a query. The parameter 'query' is the selection criteria and the options parameter is the extra options, like - limit, skip, hint and are optional.
The following statement returns total number of students in a collection.
MongoDB count() with find()
We can also use count() with find() query. The given statement returns total number of students of class '5C'.