I'm trying to upload some data into Azure Cosmos Db container via CreateItemAsync() method, with this code:
Database partnersDb = GetCosmosDb();
Container partnersContainer = GetCosmosContainer(partnersDb);
try
{
ItemResponse<PartnerInfo> partnersResponse = await partnersContainer.CreateItemAsync(partner, new PartitionKey(partner.Id));
}
catch (CosmosException e) when (e.StatusCode == HttpStatusCode.Conflict)
{
logger.LogInformation($"Item with id {partner.Id} already exists in partners database");
}
The problem is, that upon trying to upload, i get "PartitionKey extracted from document doesn't match the one specified in the header" error mentioned in the title. I've read similar topics about this, and wasn't able to find out what's wrong. I'm trying to pass value as partitionKey that is defined as [JsonProperty(PropertyName = "id")]
, moreover, container I'm trying to upload into has been created by someone in azure portal, and I do not know what PartitionKey is specified. Upon trying to run
select c.partitionkey from c
In cosmos db, i get only this for 3 items that have been created manually via "New item" option:
[
{},
{},
{}
]
Any ideas?
PartitionKeyPath
by using this codeContainerProperties properties = await container.ReadContainerAsync(); Console.WriteLine(properties.PartitionKeyPath);
– Steve Zhao