IDocumentClient.UpsertDocumentAsync メソッド

定義

オーバーロード

UpsertDocumentAsync(String, Object, RequestOptions, Boolean, CancellationToken)

Azure Cosmos DB サービスの非同期操作としてドキュメントをアップサートします。

UpsertDocumentAsync(Uri, Object, RequestOptions, Boolean, CancellationToken)

Azure Cosmos DB サービスの非同期操作としてドキュメントをアップサートします。

UpsertDocumentAsync(String, Object, RequestOptions, Boolean, CancellationToken)

Azure Cosmos DB サービスの非同期操作としてドキュメントをアップサートします。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>> UpsertDocumentAsync (string collectionLink, object document, Microsoft.Azure.Documents.Client.RequestOptions options = default, bool disableAutomaticIdGeneration = false, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertDocumentAsync : string * obj * Microsoft.Azure.Documents.Client.RequestOptions * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>>
Public Function UpsertDocumentAsync (collectionLink As String, document As Object, Optional options As RequestOptions = Nothing, Optional disableAutomaticIdGeneration As Boolean = false, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Document))

パラメーター

collectionLink
String

ドキュメントを DocumentCollection アップサートする のリンク。 例: dbs/db_rid/colls/coll_rid/

document
Object

アップサートするドキュメント オブジェクト。

options
RequestOptions

(省略可能)設定する要求オプション。 たとえば、ドキュメントの作成時に実行するトリガーを指定します。 RequestOptions

disableAutomaticIdGeneration
Boolean

(省略可能)ID の自動生成を無効にします。これが True の場合、id プロパティが Document に存在しない場合、システムは例外をスローします。

cancellationToken
CancellationToken

(省略可能) CancellationToken 取り消しの通知を受け取るために他のオブジェクトまたはスレッドが使用できる 。

戻り値

非同期操作の Document サービス応答を Task 表す オブジェクト内に含まれるアップサートされた 。

例外

または documentcollectionLink設定されていない場合。

非同期処理中に発生したエラーの統合を表します。 InnerExceptions 内を見て、実際の例外を見つけます

この例外により、さまざまな種類のエラーがカプセル化される可能性があります。 特定のエラーを特定するには、常に StatusCode プロパティを参照してください。 ドキュメントの作成時に取得できる一般的なコードは次のとおりです。

StatusCode例外の理由
400BadRequest - 指定されたドキュメントに問題が発生したことを意味します。 true であり、ID が指定されていない可能性がありますdisableAutomaticIdGeneration
403禁止 - これは、ドキュメントのアップサートを試みたコレクションがいっぱいであることを意味する可能性があります。
409競合 - これは、 の id フィールドdocumentに一致する ID が既に存在する を意味Documentします。
413RequestEntityTooLarge - つまり、 が Document 現在の最大エンティティ サイズを超えています。 制限とクォータについては、ドキュメントを参照してください。
429TooManyRequests - つまり、1 秒あたりの要求ユニット数を超えています。 DocumentClientException.RetryAfter 値を調べ、この操作を再試行するまでの待機時間を確認します。

Azure Cosmos DB では、ドキュメントを操作するためのさまざまな方法がサポートされています。 ドキュメントを拡張できる Resource

public class MyObject : Resource
{
    public string MyProperty {get; set;}
}

using (IDocumentClient client = new DocumentClient(new Uri("service endpoint"), "auth key"))
{
    Document doc = await client.UpsertDocumentAsync("dbs/db_rid/colls/coll_rid/", new MyObject { MyProperty = "A Value" });
}

ドキュメントには、JSON にシリアル化できる任意の POCO オブジェクトを指定できます(拡張元ではない場合でも) Resource

public class MyPOCO
{
    public string MyProperty {get; set;}
}

using (IDocumentClient client = new DocumentClient(new Uri("service endpoint"), "auth key"))
{
    Document doc = await client.UpsertDocumentAsync("dbs/db_rid/colls/coll_rid/", new MyPOCO { MyProperty = "A Value" });
}

Document は動的オブジェクトにすることもできます

using (IDocumentClient client = new DocumentClient(new Uri("service endpoint"), "auth key"))
{
    Document doc = await client.UpsertDocumentAsync("dbs/db_rid/colls/coll_rid/", new { SomeProperty = "A Value" } );
}

ドキュメントをアップサートし、事前トリガーと事後トリガーを実行する

using (IDocumentClient client = new DocumentClient(new Uri("service endpoint"), "auth key"))
{
    Document doc = await client.UpsertDocumentAsync(
        "dbs/db_rid/colls/coll_rid/",
        new { id = "DOC123213443" },
        new RequestOptions
        {
            PreTriggerInclude = new List<string> { "MyPreTrigger" },
            PostTriggerInclude = new List<string> { "MyPostTrigger" }
        });
}

こちらもご覧ください

適用対象

UpsertDocumentAsync(Uri, Object, RequestOptions, Boolean, CancellationToken)

Azure Cosmos DB サービスの非同期操作としてドキュメントをアップサートします。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>> UpsertDocumentAsync (Uri documentCollectionUri, object document, Microsoft.Azure.Documents.Client.RequestOptions options = default, bool disableAutomaticIdGeneration = false, System.Threading.CancellationToken cancellationToken = default);
abstract member UpsertDocumentAsync : Uri * obj * Microsoft.Azure.Documents.Client.RequestOptions * bool * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>>
Public Function UpsertDocumentAsync (documentCollectionUri As Uri, document As Object, Optional options As RequestOptions = Nothing, Optional disableAutomaticIdGeneration As Boolean = false, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Document))

パラメーター

documentCollectionUri
Uri

ドキュメントをアップサートするドキュメント コレクションの URI。

document
Object

ドキュメント オブジェクト。

options
RequestOptions

(省略可能) RequestOptions 要求の 。

disableAutomaticIdGeneration
Boolean

ID の自動生成を無効にするフラグ。

cancellationToken
CancellationToken

(省略可能) CancellationToken 取り消しの通知を受け取るために他のオブジェクトまたはスレッドが使用できる 。

戻り値

非同期操作のサービス応答を表すタスク オブジェクト。

適用対象