2017-12-26 10 views
0

컬렉션의 IndexingPolicy를 업데이트하려고합니다. 컬렉션 정의는 CreateDocumentCollectionIsNotExistsAsync를 사용할 때 잘 작동하지만 ReplaceDocumentCollectionAsync를 사용하여 Exising 컬렉션의 정의를 업데이트하려고하면 DocumentClientException이 throw됩니다. .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() 

코드로 업데이트되었습니다. 나는 Create/Modify 인덱스 코드를 공유하려고하므로 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

당신은 CreateDocumentCollectionIfNotExistsAsync에서 ReplaceDocumentCollectionAsync에 반환 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 인스턴스가, 호출에 의해 수정 믿지 않는다. 바꾸기 작업에는 서버에서 반환 된 리소스로만 채워지는 내부 메타 데이터가 필요합니다.