Delete document in CosmosDB through azure function

后端 未结 3 1505
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 02:11

Reading the Azure portal I\'ve understood how to make a POST, PUT and GET operation with CosmosDB through the Azure Functions. But del

3条回答
  •  滥情空心
    2021-01-07 02:26

    You could do this by binding directly to the DocumentClient itself, and delete the Document programatically.

    [FunctionName("DeleteDocument")]
    public static async Task Run(
        [TimerTrigger("00:01", RunOnStartup = true)] TimerInfo timer,
        [DocumentDB] DocumentClient client,
        TraceWriter log)
    {
        var collectionUri = UriFactory.CreateDocumentCollectionUri("ItemDb", "ItemCollection");
        var documents = client.CreateDocumentQuery(collectionUri);
    
        foreach (Document d in documents)
        {
            await client.DeleteDocumentAsync(d.SelfLink);
        }
    }
    

    See CosmosDBSamples

提交回复
热议问题