gpt4 book ai didi

azure-cosmosdb - 插入文档时响应状态码不表示成功

转载 作者:行者123 更新时间:2023-12-04 14:13:04 24 4
gpt4 key购买 nike

我的容器上有以下分区 ID:
/船只编号
我正在尝试添加此对象的集合:

public class CoachVessel
{
[JsonProperty("id")]
public string vesselId { get; set; }

[JsonProperty("imo")]
public long Imo { get; set; }

[JsonProperty("name")]
public string Name { get; set; }
}
这是我批量插入文档的代码:
 CosmosClientOptions options = new CosmosClientOptions() { AllowBulkExecution = true };
CosmosClient cosmosclient = new CosmosClient(connStr, options);
Container container = cosmosclient.GetContainer("CoachAPI", "Vessels");

List<Task> concurrentTasks = new List<Task>();
foreach (var vessel in vessels.Take(1))
{
concurrentTasks.Add(container.CreateItemAsync(vessel, new PartitionKey(vessel.vesselId)));
}
await Task.WhenAll(concurrentTasks);
我收到以下错误,但没有提供太多信息?

Microsoft.Azure.Cosmos.CosmosException: 'Response status code does notindicate success: BadRequest (400); Substatus: 1001; ActivityId: ;Reason: ();'


任何导致这种情况的指针?这是我的设置:
enter image description here
删除文档时遇到同样的问题:
CosmosClientOptions options = new CosmosClientOptions() { AllowBulkExecution = true,  MaxRetryAttemptsOnRateLimitedRequests=1000};
CosmosClient cosmosclient = new CosmosClient(connStr, options);
Container container = cosmosclient.GetContainer("CoachAPI", "Vessels");


var allItemsQuery = container.GetItemQueryIterator<string>("SELECT * FROM c.id");

List<Task> concurrentDeleteTasks = new List<Task>();

while (allItemsQuery.HasMoreResults)
{
foreach (var item in await allItemsQuery.ReadNextAsync())
{
concurrentDeleteTasks.Add(container.DeleteItemAsync<string>(item, new PartitionKey("id")));
}
}

await Task.WhenAll(concurrentDeleteTasks.Take(3));
抛出以下错误:
'响应状态码不表示成功:NotFound(404);子状态:0;

最佳答案

分区键必须与文档正文中的属性匹配。将容器的分区键更改为 /id并修复您的删除代码以正确指定分区键。例如。,

concurrentDeleteTasks.Add(container.DeleteItemAsync<string>(item, new PartitionKey(item.Id)));

关于azure-cosmosdb - 插入文档时响应状态码不表示成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62797456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com