AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/geoNear.md

Summary

Added new documentation page for the $geoNear aggregation stage in Amazon DocumentDB, including parameters, examples in MongoDB shell, Node.js, and Python, and connection details with TLS configuration

Security assessment

This change adds documentation for a geospatial query feature ($geoNear) and includes code examples with TLS connection parameters (tls=true, tlsCAFile=global-bundle.pem). While it demonstrates secure connection practices, there is no evidence this addresses a specific security vulnerability or incident. The documentation primarily focuses on feature usage rather than security remediation.

Diff

diff --git a/documentdb/latest/developerguide/geoNear.md b/documentdb/latest/developerguide/geoNear.md
index 8b1378917..a2b12721b 100644
--- a//documentdb/latest/developerguide/geoNear.md
+++ b//documentdb/latest/developerguide/geoNear.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#geoNear "Open PDF")
@@ -1,0 +3,144 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $geoNear
+
+The `$geoNear` aggregation stage returns documents in order of proximity to a specified point. It calculates the distance from the point and includes the distance in the output documents.
+
+**Parameters**
+
+  * `near`: The point from which to calculate distances, specified as GeoJSON or legacy coordinates.
+
+  * `distanceField`: The field name to store the calculated distance.
+
+  * `spherical`: Boolean indicating whether to use spherical geometry (required for GeoJSON points).
+
+  * `maxDistance`: Optional. Maximum distance from the center point.
+
+  * `minDistance`: Optional. Minimum distance from the center point.
+
+  * `query`: Optional. Additional filter criteria to apply.
+
+  * `limit`: Optional. Maximum number of documents to return.
+
+  * `key`: Optional. Field to use for geospatial query when multiple geospatial indexes exist.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates using the `$geoNear` stage to find stores nearest to a given location.
+
+**Create sample documents**
+    
+    
+    db.stores.createIndex({ location: "2dsphere" });
+    
+    db.stores.insertMany([
+      { _id: 1, name: "Store A", location: { type: "Point", coordinates: [-122.4, 37.8] } },
+      { _id: 2, name: "Store B", location: { type: "Point", coordinates: [-122.5, 37.7] } },
+      { _id: 3, name: "Store C", location: { type: "Point", coordinates: [-122.3, 37.9] } }
+    ]);
+
+**Query example**
+    
+    
+    db.stores.aggregate([
+      {
+        $geoNear: {
+          near: { type: "Point", coordinates: [-122.4, 37.8] },
+          distanceField: "distance",
+          spherical: true
+        }
+      }
+    ]);
+
+**Output**
+    
+    
+    [
+      { _id: 1, name: 'Store A', location: { type: 'Point', coordinates: [ -122.4, 37.8 ] }, distance: 0 },
+      { _id: 3, name: 'Store C', location: { type: 'Point', coordinates: [ -122.3, 37.9 ] }, distance: 13877.82 },
+      { _id: 2, name: 'Store B', location: { type: 'Point', coordinates: [ -122.5, 37.7 ] }, distance: 15557.89 }
+    ]
+
+## Code examples
+
+To view a code example for using the `$geoNear` aggregation stage, choose the tab for the language that you want to use:
+
+Node.js
+    
+    
+    
+    const { MongoClient } = require('mongodb');
+    
+    async function example() {
+      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('test');
+      const collection = db.collection('stores');
+    
+      const result = await collection.aggregate([
+        {
+          $geoNear: {
+            near: { type: "Point", coordinates: [-122.4, 37.8] },
+            distanceField: "distance",
+            spherical: true
+          }
+        }
+      ]).toArray();
+    
+      console.log(result);
+      await client.close();
+    }
+    
+    example();
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    
+    def example():
+        client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
+        db = client['test']
+        collection = db['stores']
+    
+        result = list(collection.aggregate([
+            {
+                '$geoNear': {
+                    'near': { 'type': 'Point', 'coordinates': [-122.4, 37.8] },
+                    'distanceField': 'distance',
+                    'spherical': True
+                }
+            }
+        ]))
+    
+        print(result)
+        client.close()
+    
+    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)
+
+$floor
+
+$group
+
+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.