2017-12-26 11 views
0

コレクションのIndexingPolicyを更新しようとしています。コレクション定義は、CreateDocumentCollectionIsNotExistsAsyncを使用する場合は正常に機能しますが、ReplaceDocumentCollectionAsyncを使用してExisingコレクションの定義を更新しようとすると、DocumentClientExceptionがスローされます。 .NETライブラリ1.19.1を使用します。例外の詳細は次のとおりです。ReplaceDocumentCollectionAsync DocumentClientExceptionをスローする

DocDBTrace Error: 0 : DocumentClientException with status code NotFound, message: The value '' specified for query '$resolveFor' is invalid., inner exception: null, and response headers: null 
DocDBTrace Error: 0 : Operation will NOT be retried. Current attempt 0, Exception: Microsoft.Azure.Documents.NotFoundException: The value '' specified for query '$resolveFor' is invalid., documentdb-dotnet-sdk/1.19.1 Host/64-bit MicrosoftWindowsNT/6.2.9200.0 
    at Microsoft.Azure.Documents.DocumentServiceRequest..ctor(OperationType operationType, ResourceType resourceType, String path, Stream body, AuthorizationTokenType authorizationTokenType, NameValueCollection headers) 
    at Microsoft.Azure.Documents.DocumentServiceRequest.Create(OperationType operationType, String relativePath, Resource resource, ResourceType resourceType, AuthorizationTokenType authorizationTokenType, NameValueCollection headers, SerializationFormattingPolicy formattingPolicy, JsonSerializerSettings settings) 
    at Microsoft.Azure.Documents.Client.DocumentClient.<ReplaceDocumentCollectionPrivateAsync>d__123.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClass2.<<ExecuteAsync>b__0>d__4.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__1b.MoveNext() 

コードで更新されます。作成/変更インデックスコードを共有しようとしているので、まずCreateDocumentCollectionIfNotExistAsyncを呼び出し、コレクションが存在する場合は、インデックスポリシーを変更して最新のものと一致させます。

DocumentCollection appCollection = new DocumentCollection(); 
    appCollection.Id = CosmosDbCollectionName; 

    // Set the index policy 

    var rrdc = await cdbClient.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(CosmosDbDatabaseName), appCollection); 
    if (true == rrdc.StatusCode.IsSuccessCode()) 
    { 
     // If OK was returned, the collection already existed. 
     if (HttpStatusCode.OK == rrdc.StatusCode) 
     { 
      var rr = await _cdbClient.ReplaceDocumentCollectionAsync(appCollection).ConfigureAwait(false); 
      if (false == rr.StatusCode.IsSuccessCode()) 
       return false; 
     } 
    } 
+0

'DocumentClient.ReplaceDocumentCollectionAsync()'の呼び出しはどのようになりますか? –

答えて

0

あなたはReplaceDocumentCollectionAsyncCreateDocumentCollectionIfNotExistsAsyncから返さDocumentCollectionはリソースのインスタンスを渡す必要があります。例えば

DocumentCollection appCollectionSpec = new DocumentCollection(); 
appCollection.Id = CosmosDbCollectionName; 

// Set the index policy 

ResourceResponse<DocumentCollection> rrdc = await cdbClient.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(CosmosDbDatabaseName), appCollectionSpec); 
if (true == rrdc.StatusCode.IsSuccessCode()) 
{ 
    // If OK was returned, the collection already existed. 
    if (HttpStatusCode.OK == rrdc.StatusCode) 
    { 
     var rr = await _cdbClient.ReplaceDocumentCollectionAsync(rrdc.Resource).ConfigureAwait(false); 
     if (false == rr.StatusCode.IsSuccessCode()) 
      return false; 
    } 
} 

私はそれが「スペック」オブジェクトとして扱われるようCreateDocumentCollectionIfNotExistsに渡されDocumentCollectionはインスタンスは、呼び出しで変更されるとは思いません。置換操作では、サーバーから返されたリソースによってのみデータが取り込まれる内部メタデータが必要です。

関連する問題