You can use countDocuments() method.
Definition:
The countDocuments() method is used to count the total number of documents in a collection that matches a specified query. It provides an efficient way to retrieve the document count.
Syntax:
db.collection.countDocuments(query, options)