AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/geoWithin.md

Summary

Added comprehensive documentation for the $geoWithin operator in Amazon DocumentDB, including description, parameters, MongoDB Shell example with sample data and queries, and code examples in Node.js and Python.

Security assessment

This change adds documentation for a geospatial query operator ($geoWithin) with examples of how to use it. There is no mention of security vulnerabilities, fixes, or security features. The code examples include standard connection strings with TLS parameters, but these are routine security best practices for database connections, not new security documentation.

Diff

diff --git a/documentdb/latest/developerguide/geoWithin.md b/documentdb/latest/developerguide/geoWithin.md
index 8b1378917..bd886ac99 100644
--- a//documentdb/latest/developerguide/geoWithin.md
+++ b//documentdb/latest/developerguide/geoWithin.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#geoWithin "Open PDF")
@@ -1,0 +3,181 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $geoWithin
+
+The `$geoWithin` operator in Amazon DocumentDB is used to find documents whose location data (represented as GeoJSON objects) are completely contained within a specified shape, such as a polygon or multipolygon. This is useful for querying for objects that are located within a specific geographic region.
+
+**Parameters**
+
+  * `$geometry`: A GeoJSON object that represents the shape to query against.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates how to use the `$geoWithin` operator to find all airports located within the state of New York.
+
+**Create sample documents**
+    
+    
+    // Insert state document
+    db.states.insert({
+        "name": "New York",
+        "loc": {
+            "type": "Polygon",
+            "coordinates": [[
+                [-79.76278, 45.0],
+                [-73.94, 45.0],
+                [-73.94, 40.5],
+                [-79.76278, 40.5],
+                [-79.76278, 45.0]
+            ]]
+        }
+    });
+    
+    // Insert airport documents
+    db.airports.insert([
+        {
+            "name": "John F. Kennedy International Airport",
+            "type": "airport",
+            "code": "JFK",
+            "loc": {
+                "type": "Point",
+                "coordinates": [-73.7781, 40.6413]
+            }
+        },
+        {
+            "name": "LaGuardia Airport",
+            "type": "airport",
+            "code": "LGA",
+            "loc": {
+                "type": "Point",
+                "coordinates": [-73.8772, 40.7769]
+            }
+        },
+        {
+            "name": "Buffalo Niagara International Airport",
+            "type": "airport",
+            "code": "BUF",
+            "loc": {
+                "type": "Point",
+                "coordinates": [-78.7322, 42.9403]
+            }
+        }
+    ]);
+
+**Query example**
+    
+    
+    var state = db.states.findOne({"name": "New York"});
+    
+    db.airports.find({
+        "loc": {
+            "$geoWithin": {
+                "$geometry": state.loc
+            }
+        }
+    }, {
+        "name": 1,
+        "type": 1,
+        "code": 1,
+        "_id": 0
+    });
+
+**Output**
+    
+    
+    [
+      {
+        "name": "John F. Kennedy International Airport",
+        "type": "airport",
+        "code": "JFK"
+      },
+      {
+        "name": "LaGuardia Airport",
+        "type": "airport",
+        "code": "LGA"
+      }
+    ]
+
+## Code examples
+
+To view a code example for using the `$geoWithin` command, choose the tab for the language that you want to use:
+
+Node.js
+    
+    
+    
+    const { MongoClient } = require('mongodb');
+    
+    async function findAirportsWithinState(stateName) {
+      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 stateDoc = await db.collection('states').findOne({ name: stateName }, { projection: { _id: 0, loc: 1 } });
+      const airportDocs = await db.collection('airports').find({
+        loc: {
+          $geoWithin: {
+            $geometry: stateDoc.loc
+          }
+        }
+      }, { projection: { name: 1, type: 1, code: 1, _id: 0 } }).toArray();
+    
+      console.log(airportDocs);
+    
+      await client.close();
+    }
+    
+    findAirportsWithinState('New York');
+
+Python
+    
+    
+    
+    from pymongo import MongoClient
+    
+    def find_airports_within_state(state_name):
+        try:
+            client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false')
+            db = client['test']
+            state_doc = db.states.find_one({'name': state_name}, {'_id': 0, 'loc': 1})
+            airport_docs = db.airports.find({
+                'loc': {
+                    '$geoWithin': {
+                        '$geometry': state_doc['loc']
+                    }
+                }
+            }, {'name': 1, 'type': 1, 'code': 1, '_id': 0})
+            
+            return list(airport_docs)
+        except Exception as e:
+            print(f'Error: {e}')
+        finally:
+            client.close()
+    
+    airports = find_airports_within_state('New York')
+    print(airports)
+
+![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)
+
+$geoIntersects
+
+$maxDistance
+
+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.