Share via


你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Container.ReplaceContainerAsync 方法

定义

ContainerProperties将 Azure Cosmos 服务中的 作为异步操作替换。

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse> ReplaceContainerAsync (Microsoft.Azure.Cosmos.ContainerProperties containerProperties, Microsoft.Azure.Cosmos.ContainerRequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceContainerAsync : Microsoft.Azure.Cosmos.ContainerProperties * Microsoft.Azure.Cosmos.ContainerRequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ContainerResponse>
Public MustOverride Function ReplaceContainerAsync (containerProperties As ContainerProperties, Optional requestOptions As ContainerRequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ContainerResponse)

参数

containerProperties
ContainerProperties

ContainerProperties 对象。

requestOptions
ContainerRequestOptions

(可选) 容器请求的选项。

cancellationToken
CancellationToken

(表示请求取消的可选) CancellationToken

返回

包含 Task 的 , ContainerResponse 它包装 ContainerProperties 包含替换资源记录的 。

例外

此异常可以封装许多不同类型的错误。 若要确定特定错误,请始终查看 StatusCode 属性。 创建文档时可能会获取的一些常见代码包括:

StatusCode异常原因
404NotFound - 这意味着你尝试读取的资源不存在。
429TooManyRequests - 这意味着已超出每秒请求单位数。 请参阅 DocumentClientException.RetryAfter 值,了解在重试此操作之前应等待多长时间。

示例

更新容器以禁用自动索引

ContainerProperties containerProperties = containerReadResponse;
containerProperties.IndexingPolicy.Automatic = false;
ContainerResponse response = await container.ReplaceContainerAsync(containerProperties);
ContainerProperties replacedProperties = response;

适用于