UUID()
On this page本页内容
Definition释义
Generates a BSON UUID object.生成BSON UUID
对象。
UUID()
has the following syntax:具有以下语法:
UUID(<string>)
-
Parameter参数Type类型Description描述hex
string Optional.可选的。Specify a 36 character string to convert to a UUID BSON object.指定一个36个字符的字符串以转换为UUID BSON对象。If not provided, MongoDB generates a random UUID in RFC 4122 v4如果没有提供,MongoDB会以RFC 4122 v4format.
格式生成一个随机UUID。
Returns:返回值:A BSON UUID object.BSON UUID对象。
Example实例
Convert Character String to UUID将字符串转换为UUID
Create a 36 character string you wish to convert to a UUID:创建一个36个字符的字符串,以便转换为UUID:
var myuuid = '3b241101-e2bb-4255-8caf-4136c566a962'
The following command outputs the 以下命令将myuuid
variable as a BSON UUID object:myuuid
变量输出为BSON UUID对象:
UUID(myuuid)
This command generates the following output:此命令生成以下输出:
UUID("3b241101-e2bb-4255-8caf-4136c566a962")
Generate Random UUID生成随机UUID
You can run the 您可以在不指定参数的情况下运行UUID()
method without specifying an argument to generate a random UUID:UUID()
方法来生成随机UUID:
UUID()
This command outputs a random UUID in the following form:此命令以以下形式输出一个随机UUID:
UUID("dee11d4e-63c6-4d90-983c-5c9f1e79e96c")