$createUUID
定義
The $createUUID
expression takes no arguments and returns
a UUID BSON type (i.e. a BinData with subtype=4). The UUID
is a version 4 UUID conforming to RFC 4122.
構文
The $createUUID
expression is an empty object {}
and has no internal syntax.
動作
Pass $createUUID: {}
in your aggregation pipeline to generate a UUID value.
例
The following examples demonstrate a basic use of the $createUUID
expression.
{$project: { a: {$createUUID: {}} b: {$createUUID: {}} }}
{ a: UUID('e14ac078-b627-48e8-b009-77dbd7150e75') b: UUID(‘f18689fe-6dfc-4823-a01e-32792f0091fe’) }
You can use a $toString
expression to convert the output of your $createUUID
expression to a string value.
{$project: { a: {$toString: {$createUUID: {}}} }}
{ a: 'e14ac078-b627-48e8-b009-77dbd7150e75' }
{$project: { a: {$createUUID: {“foo”: “bar”}} }}
Error– $createUUID does not accept arguments.