Delete document in CosmosDB through azure function

后端 未结 3 1499
隐瞒了意图╮
隐瞒了意图╮ 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:14

    I combined:

    • HTTP trigger
    • CosmoDB DocumentClient Input
    • CosmoDB Input with look up ID from query string
    public static async Task Run(
                [HttpTrigger(AuthorizationLevel.Function, "delete")] HttpRequest req,
                [CosmosDB(databaseName: "storage", collectionName: "pizza", Id = "{Query.id}", PartitionKey = "{Query.storeId}", ConnectionStringSetting = "..."] Document document,
                [CosmosDB(databaseName: "storage", collectionName: "pizza", ConnectionStringSetting = ...)] DocumentClient client)
            {
                string storeId = req.Query["storeId"];
    
                if(document == null || string.IsNullOrEmpty(storeId))
                    return new BadRequestResult();
    
                await client.DeleteDocumentAsync(document.SelfLink, new RequestOptions() { PartitionKey = new PartitionKey(storeId) });
    
                return new OkResult();
            }
    

提交回复
热议问题