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

collection.estimated_document_count(
    *,
    max_time_ms: int,
) -> int:
collection.estimatedDocumentCount(
  options?: {
    maxTimeMS?: number,
  },
): Promise<number>
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

max_time_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 object.

Name Type Summary

options

WithTimeout

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

Properties of options
Name Type Summary

maxTimeMS

number

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 object.

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.datastax.astra.client.collection;

import com.datastax.astra.client.Collection;
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.model.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