As per MongoDB pymongo documentation here
The count() method is
deprecated and not supported in a transaction. Please use count_documents() instead.
DEPRECATED - Get the size of the results set for this query.
The count() method is deprecated and not supported in a transaction. Returns the number of documents in the results set for this query. Does not take limit() and skip() into account by default -
set with_limit_and_skip to True if that is the desired behavior. Raises OperationFailure on a database error.
When used with
MongoDB >= 2.6, count() uses any hint() applied to the query. In the following example the hint is passed to the count command:
The count() method obeys the read_preference of the Collection instance on which find() was called.
Changed in version 3.7: Deprecated.
Changed in version 2.8: The count() method now supports hint().
count_documents(filter, session=None, kwargs)
Count the number of documents in this collection.
The count_documents() method is supported in a transaction.
All optional parameters should be passed as keyword arguments to this method. Valid options include:
- skip (int): The number of matching documents to skip before returning
- limit (int): The maximum number of documents to count.
- maxTimeMS (int): The maximum amount of time to allow this operation
to run, in milliseconds.
- collation (optional): An instance of
Collation. This option is only supported on MongoDB 3.4 and
- hint (string or list of tuples): The index to use. Specify either the
index name as a string or the index specification as a list of tuples
(e.g. [(‘a’, pymongo.ASCENDING), (‘b’, pymongo.ASCENDING)]). This
option is only supported on MongoDB 3.6 and above.
The count_documents() method obeys the read_preference of this Collection.
Note When migrating from count() to count_documents() the following query operators must be replaced:
$near $geoWithin with $center
$nearSphere $geoWithin with $centerSphere
$expr requires MongoDB 3.6+
For your further ref here and here