So the problem that I am encoutring is that I can't use "ID" again, it keeps giving me error for my CosmosDBOutput, I'm not sure why that is but I need help with this if anyone can help fix it.
Here is the Code i have so far and I am using .Net 6 LTS using C#
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Azure.Functions.Worker;
using System.Net.Http;
using System.Text;
namespace Company.Function
{
public static class GetResumeCounter
{
[FunctionName("GetResumeCounter")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[CosmosDBInput(databaseName:"AzureResume", containerName: "Counter", Connection = "AzureResumeConnectionString", Id = "1", PartitionKey = "1")] Counter counter,
[CosmosDBOutput(databaseName:"AzureResume", containerName: "Counter", Connection = "AzureResumeConnectionString", Id = "1", PartitionKey = "1")] out Counter updatedcounter,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
updatedcounter = counter;
updatedcounter.Count += 1;
var jsonToRetun = JsonConvert.SerializeObject(counter);
return new HttpResponseMessage(System.Net.HttpStatusCode.OK)
{
Content = new StringContent(jsonToRetun, Encoding.UTF8, "application/json")
};
}
}
}
I am trying to get it to build using dotnet build but I keep getting the error: The type or namespace name 'Id' could not be found (are you missing a using directive or an assembly reference?)
for my CosmosDBOutput please help
As David Mentioned
Idproperty does not exist in[CosmosDbOutput]You can use
CosmosClientto update the existing data, as[CosmosDbOutput]overrides the data.This worked for me.
My Code :
Before data:
OUTPUT:After executing function: