AWS Security ChangesHomeSearch

AWS documentdb documentation change

Service: documentdb · 2026-03-31 · Documentation low

File: documentdb/latest/developerguide/collStats.md

Summary

Added comprehensive documentation for the $collStats aggregation stage in Amazon DocumentDB, including parameters, MongoDB shell example with output, and code examples in Node.js and Python

Security assessment

This change adds standard documentation for a database statistics aggregation stage. The code examples include TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem) which are standard security practices for DocumentDB connections, but this is not new security documentation - it's just showing standard connection strings. There's no evidence of addressing a specific security vulnerability or weakness.

Diff

diff --git a/documentdb/latest/developerguide/collStats.md b/documentdb/latest/developerguide/collStats.md
index 8b1378917..c293a6cd5 100644
--- a//documentdb/latest/developerguide/collStats.md
+++ b//documentdb/latest/developerguide/collStats.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#collStats "Open PDF")
@@ -1,0 +3,148 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $collStats
+
+New from version 4.0
+
+The `$collStats` aggregation stage in Amazon DocumentDB provides statistics about the specified collection, similar to the `db.collection.stats()` command in the MongoDB shell. This stage can be used to retrieve information about the collection, such as the number of documents, the total size of the collection, and various performance metrics.
+
+**Parameters**
+
+  * `latencyStats`: (optional) A document that specifies the options for collecting latency statistics. This parameter is not supported in Amazon DocumentDB.
+
+  * `recordStats`: (optional) A document that specifies the options for collecting record statistics. This parameter is not supported in Amazon DocumentDB.
+
+  * `queryExecStats`: (optional) A document that specifies the options for collecting query execution statistics. This parameter is not supported in Amazon DocumentDB.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the `$collStats` aggregation stage to retrieve statistics about a collection named `test` in the `db` database.
+
+**Create sample documents**
+    
+    
+    db.test.insertMany([
+      { "name": "John", "age": 30 },
+      { "name": "Jane", "age": 25 },
+      { "name": "Bob", "age": 35 }
+    ]);
+
+**Query example**
+    
+    
+    db.test.aggregate([
+      { $collStats: {} }
+    ]);
+
+**Output**
+    
+    
+    {
+      "ns" : "db.test",
+      "count" : 3,
+      "size" : 87,
+      "avgObjSize" : 29,
+      "storageSize" : 40960,
+      "capped" : false,
+      "nindexes" : 1,
+      "totalIndexSize" : 8192,
+      "indexSizes" : {
+        "_id_" : 8192
+      },
+      "collScans" : 0,
+      "idxScans" : 0,
+      "opCounter" : {
+        "numDocsIns" : 3,
+        "numDocsUpd" : 0,
+        "numDocsDel" : 0
+      },
+      "cacheStats" : {
+        "collBlksHit" : 0,
+        "collBlksRead" : 0,
+        "collHitRatio" : 0,
+        "idxBlksHit" : 0,
+        "idxBlksRead" : 0,
+        "idxHitRatio" : 0
+      },
+      "lastReset" : "2023-04-11T12:00:00Z",
+      "ok" : 1,
+      "operationTime" : Timestamp(1681206000, 1)
+    }
+
+## Code examples
+
+To view a code example for using the `$collStats` command, choose the tab for the language that you want to use:
+
+Node.js
+    
+
+Here's an example of how to use the `$collStats` aggregation stage in a Node.js application using the official MongoDB Node.js driver:
+    
+    
+    const { MongoClient } = require('mongodb');
+    
+    async function runCollStatsExample() {
+      const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false');
+      const db = client.db('db');
+      const collection = db.collection('test');
+    
+      const result = await collection.aggregate([
+        { $collStats: {} }
+      ]).toArray();
+    
+      console.log(result);
+    
+      await client.close();
+    }
+    
+    runCollStatsExample();
+
+Python
+    
+
+Here's an example of how to use the `$collStats` aggregation stage in a Python application using the PyMongo driver:
+    
+    
+    from pymongo import MongoClient
+    
+    def run_coll_stats_example():
+        client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
+        db = client['db']
+        collection = db['test']
+    
+        result = list(collection.aggregate([
+            { '$collStats': {} }
+        ]))
+    
+        print(result)
+    
+        client.close()
+    
+    run_coll_stats_example()
+
+![Warning](https://d1ge0kk1l5kms0.cloudfront.net/images/G/01/webservices/console/warning.png) **Javascript is disabled or is unavailable in your browser.**
+
+To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions.
+
+[Document Conventions](/general/latest/gr/docconventions.html)
+
+$cmp
+
+$concat
+
+Did this page help you? - Yes
+
+Thanks for letting us know we're doing a good job!
+
+If you've got a moment, please tell us what we did right so we can do more of it.
+
+Did this page help you? - No
+
+Thanks for letting us know this page needs work. We're sorry we let you down.
+
+If you've got a moment, please tell us how we can make the documentation better.