I’ve been trying figuring out how to setup a cosmos db client in .net web api, and not far enough.
I’ve noticed when using the cosmosdb ReadItemAsync function I always get 404 back with this response
With the following code:
public async Task<OkObjectResult> All()
{
var client = CosmosService.GetClient();
var container = client.GetDatabase("Development").GetContainer("Notes");
var result = await container.ReadItemAsync<CosmosNote>("1717482138", new PartitionKey("id"));
return Ok(result);
}
I have also tried using a different function. I have tried using ReadManyItemsAsync, which surprisingly work for wome weird reason!
public async Task<OkObjectResult> All()
{
var client = CosmosService.GetClient();
var container = client.GetDatabase("Development").GetContainer("Notes");
List<(string, PartitionKey)> itemsToFind = new()
{
("1717482138", new PartitionKey("id"))
};
var data = await container.ReadManyItemsAsync<CosmosNote>(itemsToFind);
return Ok(data);
}
I don’t get it why ReadItemAsync isn’t working, can anyone help?
Thanks!