I am trying to add a collection of this object:
public class Organization
{
[JsonProperty("id")]
public string? Id { get; set; }
[JsonProperty("name")]
public string? Name { get; set; }
[JsonProperty("address")]
public string? Address { get; set; }
[JsonProperty("createdOn")]
public DateTime CreatedOn { get; set; }
[JsonProperty("updatedOn")]
public DateTime UpdatedOn { get; set; }
[JsonProperty("owner")]
public User? Owner { get; set; }
[JsonProperty("creator")]
public User? Creator { get; set; }
[JsonProperty("lastUpdatedBy")]
public User? LastUpdatedBy { get; set; }
[JsonProperty("tenantId")]
public string? TenantId { get; set; }
}
This is my code to bulk insert the documents:
public async Task<BulkOperationResponse<Organization>> BulkCreateOrganizationDB(List<Organization> reqs)
{
BulkOperations<Organization> bulkOperations = new();
foreach (var req in reqs)
{
PartitionKey partitionKey = new(req.TenantId);
bulkOperations.Tasks.Add(_container.CreateItemAsync(req, partitionKey));
}
BulkOperationResponse<Organization> bulkResponse = await bulkOperations.ExecuteAsync();
return bulkResponse;
}
But I get the following error that does not provide much information
Response status code does not indicate success: Conflict (409); Substatus: 0; ActivityId: 1cc2c968-2ccd-4a8d-8207-1a9b71b89d33; Reason: ();
I am using tenantId
as the Partition Key in Cosmos DB..
I also tried the same approach for bulk update, and it worked correctly. How can I resolve this issue with bulk insert?