UUID() (mongosh method)
Definition
Generates a BSON UUID object.
UUID()
has the following syntax:
UUID(<string>)
- ParameterTypeDescription
hex
string
Optional. Specify a 36 character string to convert to a UUID BSON object. If not provided, MongoDB generates a random UUID in MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Example
Convert Character String to UUID
Create a 36 character string you wish to convert to a UUID:
var myuuid = '3b241101-e2bb-4255-8caf-4136c566a962' The following command outputs the
myuuid
variable as a BSON UUID object:UUID(myuuid) This command generates the following output:
UUID("3b241101-e2bb-4255-8caf-4136c566a962") Generate Random UUID
You can run the
UUID()
method without specifying an argument to generate a random UUID:UUID() This command outputs a random UUID in the following form:
UUID("dee11d4e-63c6-4d90-983c-5c9f1e79e96c") Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant