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.

Method signature

  • Python

  • TypeScript

  • Java

  • curl

The following method belongs to the astrapy.Collection class.

estimated_document_count(
  *,
  general_method_timeout_ms: int,
  request_timeout_ms: int,
  timeout_ms: int,
) -> int:

The following method belongs to the Collection class.

async estimatedDocumentCount(
  options?: {
    timeout?: number | TimeoutDescriptor,
  },
): number

The following methods belong to the com.datastax.astra.client.Collection class.

long estimatedDocumentCount()
long estimatedDocumentCount(EstimatedCountDocumentsOptions options)
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": {}
}'

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

Name Type Summary

general_method_timeout_ms

int

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 Collection or DataAPIClient object. For more information, see Timeout options.

request_timeout_ms

int

Optional. An alias for general_method_timeout_ms. Since this method issues a single HTTP request, general_method_timeout_ms and request_timeout_ms are equivalent.

timeout_ms

int

Optional. An alias for general_method_timeout_ms.

Name Type Summary

options

object

Optional. The options for this operation. See the options table for more details.

Properties of options
Name Type Summary

timeout

number | TimeoutDescriptor

Optional.

The timeout(s) to apply to this method. You can specify requestTimeoutMs and generalMethodTimeoutMs. Since this method issues a single HTTP request, these timeouts are equivalent.

Details about the timeout parameter

The TimeoutDescriptor object can contain these properties:

  • requestTimeoutMs (number): The maximum time, in milliseconds, that the client should wait for each underlying HTTP request. Default: The default value for the collection. This default is 10 seconds unless you specified a different default when you initialized the Collection or DataAPIClient object.

  • generalMethodTimeoutMs (number): The maximum time, in milliseconds, that the whole operation can take. Since this method issues a single HTTP request, generalMethodTimeoutMs and requestTimeoutMs are equivalent. If you specify both, the minimum of the two will be used. Default: The default value for the collection. This default is 30 seconds unless you specified a different default when you initialized the Collection or DataAPIClient object.

If you specify a number instead of a TimeoutDescriptor object, that number will be applied to both requestTimeoutMs and generalMethodTimeoutMs.

EstimatedCountDocumentsOptions doesn’t include any method-specific options.

The estimatedDocumentCount command doesn’t accept any parameters.

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.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax | Privacy policy | Terms of use | Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com