AWS Security ChangesHomeSearch

AWS documentdb documentation change

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

File: documentdb/latest/developerguide/convert.md

Summary

Added comprehensive documentation for the $convert operator in Amazon DocumentDB, including parameters, examples in MongoDB Shell, and code examples in Node.js and Python

Security assessment

This change adds documentation for a data conversion operator ($convert) with no mention of security vulnerabilities, patches, or security incidents. The code examples show standard connection strings with TLS enabled, which is normal security practice but not a new security feature. The change appears to be routine feature documentation.

Diff

diff --git a/documentdb/latest/developerguide/convert.md b/documentdb/latest/developerguide/convert.md
index 8b1378917..1634edfc0 100644
--- a//documentdb/latest/developerguide/convert.md
+++ b//documentdb/latest/developerguide/convert.md
@@ -0,0 +1 @@
+[](/pdfs/documentdb/latest/developerguide/developerguide.pdf#convert "Open PDF")
@@ -1,0 +3,157 @@
+[Documentation](/index.html)[Amazon DocumentDB](/documentdb/index.html)[Developer Guide](what-is.html)
+
+Example (MongoDB Shell)Code examples
+
+# $convert
+
+New from version 4.0
+
+The `$convert` operator in Amazon DocumentDB is used to convert a value from one data type to another. This operator is useful when you need to perform operations on data of different types, such as converting a string to a number or a date to a timestamp.
+
+**Parameters**
+
+  * `to`: The target data type to convert the value to. Supported values are `"string"`, `"double"`, `"long"`, `"int"`, `"date"`, and `"boolean"`.
+
+  * `from`: The current data type of the value. If not specified, Amazon DocumentDB will attempt to automatically detect the data type.
+
+  * `onError`: (optional) The value to return if the conversion fails. Can be a specific value or one of the following special values: `"null"`, `"zerofill"`, or `"error"`.
+
+  * `onNull`: (optional) The value to return if the input value is `null`. Can be a specific value or one of the following special values: `"null"`, `"zerofill"`, or `"error"`.
+
+
+
+
+## Example (MongoDB Shell)
+
+The following example demonstrates converting a string value to a date using the `$convert` operator.
+
+**Create sample documents**
+    
+    
+    db.users.insertMany([
+      { _id: 1, name: "John Doe", joinedOn: "2022-01-01" },
+      { _id: 2, name: "Jane Smith", joinedOn: "2023-02-15" },
+      { _id: 3, name: "Bob Johnson", joinedOn: "invalid date" }
+    ]);
+
+**Query example**
+    
+    
+    db.users.aggregate([
+      {
+        $project: {
+          _id: 1,
+          name: 1,
+          joinedOn: {
+            $convert: {
+              input: "$joinedOn",
+              to: "date",
+              onError: "null",
+              onNull: "null"
+            }
+          }
+        }
+      }
+    ])
+
+**Output**
+    
+    
+    [
+      { "_id" : 1, "name" : "John Doe", "joinedOn" : ISODate("2022-01-01T00:00:00Z") },
+      { "_id" : 2, "name" : "Jane Smith", "joinedOn" : ISODate("2023-02-15T00:00:00Z") },
+      { "_id" : 3, "name" : "Bob Johnson", "joinedOn" : null }
+    ]
+
+## Code examples
+
+To view a code example for using the `$convert` command, 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 users = db.collection("users");
+    
+      const results = await users.aggregate([
+        {
+          $project: {
+            _id: 1,
+            name: 1,
+            joinedOn: {
+              $convert: {
+                input: "$joinedOn",
+                to: "date",
+                onError: "null",
+                onNull: "null"
+              }
+            }
+          }
+        }
+      ]).toArray();
+    
+      console.log(results);
+      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"]
+        users = db["users"]
+    
+        results = list(users.aggregate([
+            {
+                "$project": {
+                    "_id": 1,
+                    "name": 1,
+                    "joinedOn": {
+                        "$convert": {
+                            "input": "$joinedOn",
+                            "to": "date",
+                            "onError": "null",
+                            "onNull": "null"
+                        }
+                    }
+                }
+            }
+        ]))
+    
+        print(results)
+        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)
+
+$cond
+
+$count
+
+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.