Estimate document count (Python)
Estimates the number of documents in a collection.
This method only returns an estimated count. It is an alternative to getting an exact count, which is a slow and expensive operation.
The estimated count is based on current system statistics at the time the request is received by the database server.
The caller must have the SELECT permission on the system keyspace.
For more information, see Manage roles and permissions.
|
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
Returns an integer indicating the server-side estimate of the total number of documents in the collection.
Parameters
Use the estimated_document_count method, which belongs to the astrapy.Collection class.
Method signature
estimated_document_count(
*,
general_method_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> int:
| Name | Type | Summary |
|---|---|---|
|
|
Optional. The maximum time, in milliseconds, that the client should wait for the underlying HTTP request. Default: The default value for the collection. This default is 30 seconds unless you specified a different default when you initialized the |
|
|
Optional.
An alias for |
|
|
Optional.
An alias for |
Examples
The following example demonstrates how to estimate the number of documents in a collection.
Estimate document count
from astrapy import DataAPIClient
from astrapy.authentication import UsernamePasswordTokenProvider
from astrapy.constants import Environment
# Get an existing collection
client = DataAPIClient(environment=Environment.HCD)
database = client.get_database(
"API_ENDPOINT",
token=UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
keyspace="KEYSPACE_NAME",
)
collection = database.get_collection("COLLECTION_NAME")
# Estimate count
result = collection.estimated_document_count()
print(result)
Client reference
For more information, see the client reference.