如何区分在 cosmosdb 触发器中删除更新创建到 azure 函数
How to distinguish between delete update create in cosmosdb trigger to azure function
我在 cosmosdb 上创建了一个触发器到 azure 中的 azure 函数,我在文档中找不到任何如何区分删除、更新和创建的内容
{
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "input",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "pcmDevValidAppsTrigger_ConnectionString",
"databaseName": "pcmobile-dev",
"collectionName": "validApps",
"createLeaseCollectionIfNotExists": true
}
]
}
module.exports = async (context, documents) => {
context.log('Document Id: ', documents[0].id);
}
根据文档,您不能:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger - the Trigger consumes the Change Feed, and the Change Feed currently only includes inserts and updates (https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed#features-of-change-feed):
The change feed includes inserts and update operations made to items within the container. You can capture deletes by setting a "soft-delete" flag within your items (for example, documents) in place of deletes. Alternatively, you can set a finite expiration period for your items with the TTL capability. For example, 24 hours and use the value of that property to capture deletes. With this solution, you have to process the changes within a shorter time interval than the TTL expiration period.
我在 cosmosdb 上创建了一个触发器到 azure 中的 azure 函数,我在文档中找不到任何如何区分删除、更新和创建的内容
{
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "input",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "pcmDevValidAppsTrigger_ConnectionString",
"databaseName": "pcmobile-dev",
"collectionName": "validApps",
"createLeaseCollectionIfNotExists": true
}
]
}
module.exports = async (context, documents) => {
context.log('Document Id: ', documents[0].id);
}
根据文档,您不能:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger - the Trigger consumes the Change Feed, and the Change Feed currently only includes inserts and updates (https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed#features-of-change-feed):
The change feed includes inserts and update operations made to items within the container. You can capture deletes by setting a "soft-delete" flag within your items (for example, documents) in place of deletes. Alternatively, you can set a finite expiration period for your items with the TTL capability. For example, 24 hours and use the value of that property to capture deletes. With this solution, you have to process the changes within a shorter time interval than the TTL expiration period.