$toUUID
New from version 8.0.1.
The $toUUID operator in Amazon DocumentDB converts a string value to a UUID (Binary subtype 4).
Parameters
expression: An expression that resolves to a string in UUID format (for example, "12345678-1234-1234-1234-123456789abc").
Example (MongoDB Shell)
The following example shows how to use the $toUUID operator to convert string values to UUID format.
Create sample documents
db.records.insertMany([ {_id: 1, uuidStr: "550e8400-e29b-41d4-a716-446655440000"}, {_id: 2, uuidStr: "6ba7b810-9dad-11d1-80b4-00c04fd430c8"} ]);
Query example
db.records.aggregate([ { $project: { uuid: { $toUUID: "$uuidStr" } } } ]);
Output
[
{_id: 1, uuid: UUID("550e8400-e29b-41d4-a716-446655440000")},
{_id: 2, uuid: UUID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")}
]
Code examples
To view a code example for using the $toUUID operator, choose the tab for the language that you want to use: