当我从 Azure 流作业插入数据时,如何在 CosmosDB 中使用 GUID 作为 ID
How can I use a GUID as ID in CosmosDB when I insert data from Azure Streaming Job
您好,我有一个 Azure 流作业,它从事件中心获取数据并将它们插入 CosmosDB 数据库。我想在插入数据时使用 GUID 作为 id 而不是文档中的值。我怎样才能在查询中实现它?
首先,如果你只想保证id
在Cosmos DB中的唯一性,你不需要自己为它创建GUID值。
User-defined unique name of the resource (with the same partition key
value). If the user does not specify an id, an id is system generated.
您可以看到 Cosmos DB 系统由此 doc 生成项目。
其次,如果您确实想使用 GUID 作为 id 列的值进入 cosmos db,您可以使用 Javascript UDFs,Azure 流作业支持它。
我的样本js udfs
:
测试查询:
希望对你有帮助。
您好,我有一个 Azure 流作业,它从事件中心获取数据并将它们插入 CosmosDB 数据库。我想在插入数据时使用 GUID 作为 id 而不是文档中的值。我怎样才能在查询中实现它?
首先,如果你只想保证id
在Cosmos DB中的唯一性,你不需要自己为它创建GUID值。
User-defined unique name of the resource (with the same partition key value). If the user does not specify an id, an id is system generated.
您可以看到 Cosmos DB 系统由此 doc 生成项目。
其次,如果您确实想使用 GUID 作为 id 列的值进入 cosmos db,您可以使用 Javascript UDFs,Azure 流作业支持它。
我的样本js udfs
:
测试查询:
希望对你有帮助。