get_collection_count

Function get_collection_count 

Source
pub async fn get_collection_count(
    database: &Database,
    collection_name: &str,
) -> Result<usize>
Expand description

Get document count for a MongoDB collection

Returns the total number of documents in the collection.

§Arguments

  • database - MongoDB database reference
  • collection_name - Collection name (must be validated)

§Returns

Number of documents in the collection

§Security

Collection name should be validated before calling this function.

§Examples

let client = connect_mongodb("mongodb://localhost:27017/mydb").await?;
let db = client.database("mydb");
let collection = "users";
validate_table_name(collection)?;
let count = get_collection_count(&db, collection).await?;
println!("Collection '{}' has {} documents", collection, count);