AWS documentdb documentation change
Summary
Added comprehensive documentation for the $near operator in Amazon DocumentDB, including parameters, index requirements, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
This change adds standard documentation for a geospatial query operator ($near) with no mention of security vulnerabilities, patches, or security incidents. The code examples include standard TLS connection parameters (tls=true, tlsCAFile) which are normal secure connection practices for DocumentDB, not new security features. The change appears to be routine feature documentation.
Diff
diff --git a/documentdb/latest/developerguide/near.md b/documentdb/latest/developerguide/near.md index 8b1378917..4861a1238 100644 --- a//documentdb/latest/developerguide/near.md +++ b//documentdb/latest/developerguide/near.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#near "Open PDF") @@ -1,0 +3,185 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $near + +The `$near` operator in Amazon DocumentDB is used to find documents that are geographically near a specified point. It returns documents ordered by distance, with the closest documents first. This operator requires a 2dsphere geospatial index and is useful for proximity queries on location data. + +**Parameters** + + * `$geometry`: A GeoJSON Point object that defines the center point for the near query. + + * `$maxDistance`: (optional) The maximum distance in meters from the specified point that a document can be to match the query. + + * `$minDistance`: (optional) The minimum distance in meters from the specified point that a document can be to match the query. + + + + +**Index Requirements** + + * `2dsphere index`: Required for geospatial queries on GeoJSON Point data. + + + + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$near` operator to find the nearest restaurants to a specific location in Seattle, Washington. + +**Create sample documents** + + + db.usarestaurants.insert([ + { + "name": "Noodle House", + "city": "Seattle", + "state": "Washington", + "rating": 4.8, + "location": { "type": "Point", "coordinates": [-122.3517, 47.6159] } + }, + { + "name": "Pike Place Grill", + "city": "Seattle", + "state": "Washington", + "rating": 4.2, + "location": { "type": "Point", "coordinates": [-122.3403, 47.6062] } + }, + { + "name": "Lola", + "city": "Seattle", + "state": "Washington", + "rating": 4.5, + "location": { "type": "Point", "coordinates": [-122.3407, 47.6107] } + } + ]); + +**Create 2dsphere index** + + + db.usarestaurants.createIndex({ "location": "2dsphere" }); + +**Query example with GeoJSON Point** + + + db.usarestaurants.find({ + location: { + $near: { + $geometry: { + type: "Point", + coordinates: [-122.3516, 47.6156] + }, + $maxDistance: 100, + $minDistance: 10 + } + } + }); + +**Output** + + + { + "_id" : ObjectId("69031ec9ea1c2922a1ce5f4a"), + "name" : "Noodle House", + "city" : "Seattle", + "state" : "Washington", + "rating" : 4.8, + "location" : { + "type" : "Point", + "coordinates" : [ -122.3517, 47.6159 ] + } + } + +## Code examples + +To view a code example for using the `$near` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function findNearbyRestaurants() { + 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 restaurants = db.collection('usarestaurants'); + + // Create 2dsphere index + await restaurants.createIndex({ "location": "2dsphere" }); + + const result = await restaurants.find({ + location: { + $near: { + $geometry: { + type: "Point", + coordinates: [-122.3516, 47.6156] + }, + $maxDistance: 100, + $minDistance: 10 + } + } + }).toArray(); + + console.log(result); + + client.close(); + } + + findNearbyRestaurants(); + +Python + + + + from pymongo import MongoClient + + def find_nearby_restaurants(): + client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') + db = client['test'] + restaurants = db['usarestaurants'] + + # Create 2dsphere index + restaurants.create_index([("location", "2dsphere")]) + + result = list(restaurants.find({ + 'location': { + '$near': { + '$geometry': { + 'type': 'Point', + 'coordinates': [-122.3516, 47.6156] + }, + '$maxDistance': 100, + '$minDistance': 10 + } + } + })) + + print(result) + + client.close() + + find_nearby_restaurants() + + **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) + +$minDistance + +$nearSphere + +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.