我有一个 Azure Function,其输出绑定(bind)到 Azure Cosmos DB 以保存项目。我正在尝试在项目级别设置 TimeToLive (我知道 TTL 必须打开才能使容器正常工作)。在容器级别,TTL 通过门户启用为 -1。有没有办法通过属性通过每个元素的 OutputBinding 设置 TTL?
我的绑定(bind):
{
"type": "cosmosDB",
"direction": "out",
"name": "outputDocument",
"databaseName": "myDatabase",
"collectionName": "myCollection",
"createIfNotExists": true,
"PartitionKey": "/customerId",
"defaultTtl": -1, //doesn't work and has to be set via Azure Portal
"connectionStringSetting": "CosmosDbConnectionString"
}
当然还有我将数据写入 Cosmos DB 的 index.ts 部分:
const httpTrigger: AzureFunction = async function (context: Context, eventGridEvent: EventGridEvent<DTO>): Promise<void> {
context.bindings.outputDocument = JSON.stringify(eventGridEvent.data);
}
export default HttpTrigger;
最佳答案
该项目需要添加一个“ttl”属性。
假设您的 eventGridEvent.data
包含您要保存的完整文档,您可以执行以下操作:
var item = eventGridEvent.data;
item["ttl"] = 60; // 60 seconds
context.bindings.outputDocument = JSON.stringify(item);
关于node.js - 从 Azure Function (Node.JS) 设置项目的 TimeToLive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74234730/