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.
|
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
# Get an existing collection
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT", token="APPLICATION_TOKEN"
)
collection = database.get_collection("COLLECTION_NAME")
# Estimate count
result = collection.estimated_document_count()
print(result)
Client reference
For more information, see the client reference.