簡體   English   中英

無法使用文檔鏈接刪除 Azure Cosmos DB 中的文檔 - Java Async V2

[英]Unable to delete document in Azure Cosmos DB with Document Link - Java Async V2

我正在嘗試使用帶有文檔鏈接的 Java CosmosDB Async v2 庫刪除我的 Azure Cosmos DB 集合中的一個文檔。 每次我嘗試對文檔執行刪除操作時都會遇到Resource not found問題。 我不確定我錯過了什么。

這是我到目前為止所擁有的:

public Document deleteDocument(String docId, String collectionName){
    RequestOptions options = new RequestOptions();
    PartitionKey key = new PartitionKey(docId);
    options.setPartitionKey(key);
    String documentLink = String.format("/dbs/%s/colls/%s/docs/%s", this.databaseName, collectionName, docId);
    LOGGER.info("DOCUMENT LINK:" + documentLink);
    return this.client.deleteDocument(documentLink, options).next().block().getResource();
  }

這是來自 Azure CosmosDB 的文檔信息: 文件資料

輸入:

this.deleteDocument("beff44de-914a-4250-80c3-108b71989720", "SravanCollection");

謝謝

您可以在 V4 中執行以下操作:

public Mono<CosmosAsyncItemResponse> deleteBookByID(String id, String partitionKey) {
    return container.deleteItem(id, new PartitionKey(partitionKey));}

您可以在此處找到完整的示例應用程序: https://github.com/RaviTella/SpringBootWebFluxCosmosSQL/tree/master/ReadingListWebApp

這應該在 V2 中工作。 確保為分區鍵和 id 傳遞正確的值:

 private void deleteBookObservable(String id, String partitionKey) {
    String documentLink = String.format("/dbs/%s/colls/%s/docs/%s", databaseName, 
     collectionName, id);
    RequestOptions reqOpts = new RequestOptions();
    reqOpts.setPartitionKey(new PartitionKey(partitionKey));
    Observable<ResourceResponse<Document>> deleteObservable =
        getClient().deleteDocument(documentLink, reqOpts).toBlocking().first();  
  }
  

強烈建議使用 V4 進行所有新開發。 從 v2 到 v4 存在重大變化。 V4 使用 Reactor 核心實現反應式擴展。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM