AWS documentdb documentation change
Summary
Added new documentation page for the $hour operator in Amazon DocumentDB, including syntax, parameters, MongoDB shell examples, and code examples in Node.js and Python
Security assessment
The change adds documentation for a date/time operator ($hour) with no mention of security vulnerabilities, patches, or incidents. However, the code examples include TLS configuration (tls=true&tlsCAFile=global-bundle.pem) which demonstrates secure connection practices for DocumentDB. This shows security best practices but is not addressing a specific security issue.
Diff
diff --git a/documentdb/latest/developerguide/hour.md b/documentdb/latest/developerguide/hour.md index 8b1378917..86b25f119 100644 --- a//documentdb/latest/developerguide/hour.md +++ b//documentdb/latest/developerguide/hour.md @@ -0,0 +1 @@ +[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#hour "Open PDF") @@ -1,0 +3,179 @@ +[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html) + +Example (MongoDB Shell)Code examples + +# $hour + +The `$hour` operator extracts the hour component from a date or timestamp field. + +**Parameters** + + * `dateExpression`: The date to which the operator is applied. This must resolve to a valid BSON date (e.g., a field like $createdAt or a date literal). + + + + +A parameter can also be specified as a document in the following format: + +{ date: `<dateExpression>`, timezone: `<timezoneExpression>` } + +This allows to apply timezone-aware date operations. + + + - `<tzExpression>`: (optional) The timezone of the operation result. It must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is in UTC. + +## Example (MongoDB Shell) + +The following example demonstrates how to use the `$hour` operator to extract the hour component from a date field and group the data accordingly. + +**Create sample documents** + + + db.events.insertMany([ + { timestamp: new Date("2023-04-01T10:30:00Z") }, + { timestamp: new Date("2023-04-01T12:45:00Z") }, + { timestamp: new Date("2023-04-02T08:15:00Z") }, + { timestamp: new Date("2023-04-02T16:20:00Z") }, + { timestamp: new Date("2023-04-03T23:59:00Z") } + ]); + +**Query example** + + + db.events.aggregate([ + { + $project: { + hour: { $hour: "$timestamp" } + } + }, + { + $group: { + _id: "$hour", + count: { $sum: 1 } + } + }, + { + $sort: { _id: 1 } + } + ]); + +**Output** + + + [ + { "_id": 8, "count": 1 }, + { "_id": 10, "count": 1 }, + { "_id": 12, "count": 1 }, + { "_id": 16, "count": 1 }, + { "_id": 23, "count": 1 } + ] + +This query groups the events by the hour component of the `timestamp` field and counts the number of events for each hour. + +## Code examples + +To view a code example for using the `$hour` command, choose the tab for the language that you want to use: + +Node.js + + + + const { MongoClient } = require('mongodb'); + + async function example() { + const client = new MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); + + try { + await client.connect(); + const db = client.db('test'); + const collection = db.collection('events'); + + const result = await collection.aggregate([ + { + $project: { + hour: { $hour: "$timestamp" } + } + }, + { + $group: { + _id: "$hour", + count: { $sum: 1 } + } + }, + { + $sort: { _id: 1 } + } + ]).toArray(); + + console.log(result); + } catch (error) { + console.error('Error occurred:', error); + } finally { + await client.close(); + } + } + + example(); + +Python + + + + from pymongo import MongoClient + from datetime import datetime + + def example(): + try: + 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.events + + result = list(collection.aggregate([ + { + "$project": { + "hour": {"$hour": "$timestamp"} + } + }, + { + "$group": { + "_id": "$hour", + "count": {"$sum": 1} + } + }, + { + "$sort": {"_id": 1} + } + ])) + + print(result) + + except Exception as e: + print(f"An error occurred: {e}") + + finally: + client.close() + + example() + + **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) + +$gte + +$ifNull + +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.