Navigation
This version of the documentation is archived and no longer supported.
UUID()
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.
Changed in version 3.6: In earlier versions of the mongo shell,
UUID required a hexadecimal string argument. See the
3.4 manual.
|
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:
Changed in version 3.6: In earlier versions of the mongo
shell,
UUID
required a hexadecimal string argument.