- Reference >
mongo
Shell Methods >- Object Constructors and Methods >
- UUID()
UUID()¶
On this page
Definition¶
Generates a BSON UUID object.
UUID()
has the following syntax:
Parameter | Type | Description |
---|---|---|
hex |
string | Optional. Specify a 36 character string to convert to a UUID BSON object. If not provided, MongoDB generates a random UUID in RFC 4122 v4 format. |
returns: | A BSON UUID object. |
---|
Example¶
Convert Character String to UUID¶
Create a 36 character string you wish to convert to a UUID:
The following command outputs the myuuid
variable as a BSON UUID object:
This command generates the following output:
Generate Random UUID¶
You can run the UUID()
method without
specifying an argument to generate a random UUID:
This command outputs a random UUID in the following form: