AWS documentdb documentation change
Summary
Added new documentation page for the $nearSphere operator in Amazon DocumentDB, including operator description, parameters, MongoDB shell example, and code examples in Node.js and Python
Security assessment
This change adds standard documentation for a geospatial query operator ($nearSphere) with no mention of security vulnerabilities, patches, or security incidents. The code examples include standard TLS connection parameters (tls=true, tlsCAFile) which are routine security best practices for DocumentDB connections, but these are not new security features being documented.
Diff
diff --git a/documentdb/latest/developerguide/nearSphere.md b/documentdb/latest/developerguide/nearSphere.md index 8b1378917..9c6bdad54 100644 --- a//documentdb/latest/developerguide/nearSphere.md +++ b//documentdb/latest/developerguide/nearSphere.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#nearSphere "Open PDF") @@ -1,0 +3,153 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $nearSphere + +The `$nearSphere` operator in Amazon DocumentDB is used to find documents that are within a specified distance of a geospatial point. This operator is particularly useful for geo-spatial queries, such as finding all restaurants within a certain radius of a given location. + +**Parameters** + + * `$geometry`: A GeoJSON object that represents the reference point. Must be a `Point` object with `type` and `coordinates` fields. + + * `$minDistance`: (optional) The minimum distance (in meters) from the reference point that documents must be. + + * `$maxDistance`: (optional) The maximum distance (in meters) from the reference point that documents must be. + + + + +## Example (MongoDB Shell) + +In this example, we will find all restaurants within 2 kilometers (2000 meters) of a specific location in Seattle, WA. + +**Create sample documents** + + + db.usarestaurants.insert([ + { + name: "Noodle House", + location: { type: "Point", coordinates: [-122.3516, 47.6156] } + }, + { + name: "Pike Place Grill", + location: { type: "Point", coordinates: [-122.3403, 47.6101] } + }, + { + name: "Seattle Coffee Co.", + location: { type: "Point", coordinates: [-122.3339, 47.6062] } + } + ]); + +**Query example** + + + db.usarestaurants.find({ + location: { + $nearSphere: { + $geometry: { + type: "Point", + coordinates: [-122.3516, 47.6156] + }, + $minDistance: 1, + $maxDistance: 2000 + } + } + }, { + name: 1 + }); + +**Output** + + + { "_id" : ObjectId("611f3da985009a81ad38e74b"), "name" : "Noodle House" } + { "_id" : ObjectId("611f3da985009a81ad38e74c"), "name" : "Pike Place Grill" } + +## Code examples + +To view a code example for using the `$nearSphere` 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'); + + const result = await restaurants.find({ + location: { + $nearSphere: { + $geometry: { + type: "Point", + coordinates: [-122.3516, 47.6156] + }, + $minDistance: 1, + $maxDistance: 2000 + } + } + }, { + projection: { name: 1 } + }).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 + + result = list(restaurants.find({ + 'location': { + '$nearSphere': { + '$geometry': { + 'type': 'Point', + 'coordinates': [-122.3516, 47.6156] + }, + '$minDistance': 1, + '$maxDistance': 2000 + } + } + }, { + 'name': 1 + })) + + 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) + +$near + +Query and projection operators + +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.