Estimate document count
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
-
Python
-
TypeScript
-
Java
-
curl
Returns an integer indicating the server-side estimate of the total number of documents in the collection.
Returns a promise that resolves to an integer indicating the server-side estimate of the total number of documents in the collection.
Returns a long
indicating the server-side estimate of the total number of documents in the collection.
The response includes a status.count
property, which is an integer indicating the server-side estimate of the total number of documents in the collection.
Example response:
{
"status": {
"count": 37500
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
curl
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 |
Use the estimatedDocumentCount
method, which belongs to the Collection
class.
Method signature
async estimatedDocumentCount(
options?: {
timeout?: number | TimeoutDescriptor,
},
): number
Name | Type | Summary |
---|---|---|
|
|
Optional.
The options for this operation. See the |
Name | Type | Summary |
---|---|---|
|
|
Optional. The timeout(s) to apply to this method.
You can specify Details about the
|
Use the estimatedDocumentCount
method, which belongs to the com.datastax.astra.client.Collection
class.
Method signature
long estimatedDocumentCount()
long estimatedDocumentCount(EstimatedCountDocumentsOptions options)
EstimatedCountDocumentsOptions
doesn’t include any method-specific options.
The estimatedDocumentCount
command doesn’t accept any parameters.
Command signature
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/COLLECTION_NAME" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"estimatedDocumentCount": {}
}'
Examples
The following example demonstrates how to estimate the number of documents in a collection.
Estimate document count
-
Python
-
TypeScript
-
Java
-
curl
from astrapy import DataAPIClient, exceptions
# Get an existing collection
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")
collection = database.get_collection("COLLECTION_NAME")
# Estimate count
result = collection.estimated_document_count()
print(result)
import { DataAPIClient, TooManyDocumentsToCountError } from '@datastax/astra-db-ts';
// Get an existing collection
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');
const collection = database.collection('COLLECTION_NAME');
(async function () {
// Estimate count
const result = await collection.estimatedDocumentCount();
console.log(result);
})();
package com.examples;
import com.datastax.astra.client.collections.Collection;
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.collections.definition.documents.Document;
public class EstimateCount {
public static void main(String[] args) {
// Get an existing collection
Collection<Document> collection = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
.getDatabase("ASTRA_DB_API_ENDPOINT")
.getCollection("COLLECTION_NAME");
// Estimate count
long result = collection.estimatedDocumentCount();
System.out.println(result);
}
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_COLLECTION" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"estimatedDocumentCount": {}
}'
Client reference
-
Python
-
TypeScript
-
Java
-
curl
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
Client reference documentation is not applicable for HTTP.