2017-03-02 5 views
0

私はいくつかの文書を含むコレクションを持っています。私のアプリケーションでは、まずこのコレクションを作成してからドキュメントを挿入します。また、要件に基づいて、コレクションを切り捨て(すべての文書を削除する)必要があります。私は上記のコードでは、私のこのpurpose-AzureドキュメントDB - Java 1.9.5 |許可エラー

DocumentClient documentClient = getConnection(masterkey, server, portNo); 
List<Database> databaseList = documentClient.queryDatabases("SELECT * FROM root r WHERE r.id='" + schemaName + "'", null).getQueryIterable().toList(); 
DocumentCollection collection = null; 

Database databaseCache = (Database)databaseList.get(0); 

List<DocumentCollection> collectionList = documentClient.queryCollections(databaseCache.getSelfLink(), "SELECT * FROM root r WHERE r.id='" + collectionName + "'", null).getQueryIterable().toList(); 

// truncate logic 
if (collectionList.size() > 0) { 
    collection = ((DocumentCollection) collectionList.get(0)); 

    if (truncate) { 
     try { 
      documentClient.deleteDocument(collection.getSelfLink(), null); 
     } catch (DocumentClientException e) { 
      e.printStackTrace(); 
     } 
    } 

} else { // create logic 
    RequestOptions requestOptions = new RequestOptions(); 
    requestOptions.setOfferType("S1"); 

    collection = new DocumentCollection(); 
    collection.setId(collectionName); 
    try { 
     collection = documentClient.createCollection(databaseCache.getSelfLink(), collection, requestOptions).getResource(); 
    } catch (DocumentClientException e) { 
     e.printStackTrace(); 
    } 

ために、次のコードを書かれている文書のDBのJava APIを使用して、私は成功した新しいコレクションを作成することができています。また、このコレクションにも文書を挿入することができます。しかし、コレクションを切り詰めているうちに、私はエラー以下になっています。

com.microsoft.azure.documentdb.DocumentClientException: The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'delete 
colls 
eyckqjnw0ae= 

私はAzure Document DB Java APIバージョン1.9.5を使用しています。 私のコードでエラーを指摘できる場合、またはコレクションを切り捨てる他の方法がある場合は、大きな助けになります。私は本当にここで何か助けに感謝します。

答えて

0

あなたの説明&コードによれば、この問題は以下のコードによって発生したと思います。

try { 
    documentClient.deleteDocument(collection.getSelfLink(), null); 
} catch (DocumentClientException e) { 
    e.printStackTrace(); 
} 

あなたが上記のコードを経由して文書を削除したいと思われますが、コレクションリンクに引数を渡すdocumentLink

コレクションを削除することを実際の目的としている場合は、DocumentClient.deleteCollection(collectionLink, options)という方法を使用してください。

関連する問題