我尝试过:
PartitionKey partitionKey = new PartitionKey("/sid");
CosmosItemRequestOptions options = new CosmosItemRequestOptions();
cosmosContainer.deleteItem("dbs/Student/colls/Stu/docs/104", partitionKey, options);
但是出现错误:
Aug 24, 2020 4:47:15 PM com.azure.cosmos.implementation.ClientRetryPolicy shouldRetry
SEVERE: locationEndpoint is null because ClientRetryPolicy::onBeforeRequest(.) is not invoked, probably request creation failed due to invalid options, serialization setting, etc.
Aug 24, 2020 4:47:15 PM com.azure.cosmos.implementation.RenameCollectionAwareClientRetryPolicy lambda$shouldRetry$2
SEVERE: onBeforeSendRequest is not invoked, encountered failure due to request being null
java.lang.IllegalArgumentException: Entity with the specified id does not exist in the system.
at com.azure.cosmos.implementation.RxDocumentServiceRequest.<init>(RxDocumentServiceRequest.java:190)
at com.azure.cosmos.implementation.RxDocumentServiceRequest.<init>(RxDocumentServiceRequest.java:218)
at com.azure.cosmos.implementation.RxDocumentServiceRequest.<init>(RxDocumentServiceRequest.java:243)
at com.azure.cosmos.implementation.RxDocumentServiceRequest.<init>(RxDocumentServiceRequest.java:292)
at com.azure.cosmos.implementation.RxDocumentServiceRequest.create(RxDocumentServiceRequest.java:510)
at com.azure.cosmos.implementation.RxDocumentClientImpl.deleteDocumentInternal(RxDocumentClientImpl.java:1431)
at com.azure.cosmos.implementation.RxDocumentClientImpl.lambda$deleteDocument$33(RxDocumentClientImpl.java:1418)
at com.azure.cosmos.implementation.RxDocumentClientImpl$$Lambda$525.0000000012AE2210.call(Unknown Source)
at com.azure.cosmos.implementation.ObservableHelper.lambda$inlineIfPossibleAsObs$1(ObservableHelper.java:44)
at com.azure.cosmos.implementation.ObservableHelper$$Lambda$198.00000000127DD800.call(Unknown Source)
at com.azure.cosmos.implementation.BackoffRetryUtility.lambda$executeRetry$0(BackoffRetryUtility.java:35)
at com.azure.cosmos.implementation.BackoffRetryUtility$$Lambda$80.00000000112EA850.get(Unknown Source)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)
at reactor.core.publisher.FluxRetryWhen.subscribe(FluxRetryWhen.java:79)
at reactor.core.publisher.MonoRetryWhen.subscribeOrReturn(MonoRetryWhen.java:46)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:121)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2344)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:162)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onSubscribe(MonoFlatMap.java:103)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onSubscribe(FluxMapFuseable.java:90)
at reactor.core.publisher.MonoCurrentContext.subscribe(MonoCurrentContext.java:35)
at reactor.core.publisher.Mono.subscribe(Mono.java:4213)
at reactor.core.publisher.Mono.block(Mono.java:1679)
at com.azure.cosmos.CosmosContainer.blockDeleteItemResponse(CosmosContainer.java:236)
at com.azure.cosmos.CosmosContainer.deleteItem(CosmosContainer.java:344)
at com.cosmos.poc.POC.deleteItem(POC.java:160)
at com.cosmos.poc.POC.printListContainers(POC.java:72)
at com.cosmos.poc.POC.printListDataBases(POC.java:54)
at com.cosmos.poc.POC.main(POC.java:30)
Exception in thread "main" java.lang.IllegalArgumentException: Entity with the specified id does not exist in the system.
at com.azure.cosmos.implementation.RxDocumentServiceRequest.<init>(RxDocumentServiceRequest.java:190)
at com.azure.cosmos.implementation.RxDocumentServiceRequest.<init>(RxDocumentServiceRequest.java:218)
at com.azure.cosmos.implementation.RxDocumentServiceRequest.<init>(RxDocumentServiceRequest.java:243)
at com.azure.cosmos.implementation.RxDocumentServiceRequest.<init>(RxDocumentServiceRequest.java:292)
at com.azure.cosmos.implementation.RxDocumentServiceRequest.create(RxDocumentServiceRequest.java:510)
at com.azure.cosmos.implementation.RxDocumentClientImpl.deleteDocumentInternal(RxDocumentClientImpl.java:1431)
at com.azure.cosmos.implementation.RxDocumentClientImpl.lambda$deleteDocument$33(RxDocumentClientImpl.java:1418)
at com.azure.cosmos.implementation.RxDocumentClientImpl$$Lambda$525.0000000012AE2210.call(Unknown Source)
at com.azure.cosmos.implementation.ObservableHelper.lambda$inlineIfPossibleAsObs$1(ObservableHelper.java:44)
at com.azure.cosmos.implementation.ObservableHelper$$Lambda$198.00000000127DD800.call(Unknown Source)
at com.azure.cosmos.implementation.BackoffRetryUtility.lambda$executeRetry$0(BackoffRetryUtility.java:35)
at com.azure.cosmos.implementation.BackoffRetryUtility$$Lambda$80.00000000112EA850.get(Unknown Source)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)
at reactor.core.publisher.FluxRetryWhen.subscribe(FluxRetryWhen.java:79)
at reactor.core.publisher.MonoRetryWhen.subscribeOrReturn(MonoRetryWhen.java:46)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:121)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2344)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:162)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onSubscribe(MonoFlatMap.java:103)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onSubscribe(FluxMapFuseable.java:90)
at reactor.core.publisher.MonoCurrentContext.subscribe(MonoCurrentContext.java:35)
at reactor.core.publisher.Mono.subscribe(Mono.java:4213)
at reactor.core.publisher.Mono.block(Mono.java:1679)
at com.azure.cosmos.CosmosContainer.blockDeleteItemResponse(CosmosContainer.java:236)
at com.azure.cosmos.CosmosContainer.deleteItem(CosmosContainer.java:344)
at com.cosmos.poc.POC.deleteItem(POC.java:160)
at com.cosmos.poc.POC.printListContainers(POC.java:72)
at com.cosmos.poc.POC.printListDataBases(POC.java:54)
at com.cosmos.poc.POC.main(POC.java:30)
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)
at reactor.core.publisher.Mono.block(Mono.java:1680)
... 6 more
Aug 24, 2020 4:52:11 PM com.azure.cosmos.implementation.RxDocumentClientImpl$1 getDatabaseAccountFromEndpoint
答案 0 :(得分:0)
传递给deleteItem方法的参数在您的代码段中不正确。
参数:
第一个参数 itemId :应为文档ID 。您通过了整个层次结构路径。
第二个参数 partitionKey :它应包含分区键的值。我猜你通过了字段名称。
例如,您可以参考this example以获得正确的用法。
答案 1 :(得分:0)
cosmosContainer.deleteItem(“”,新的PartitionKey(),选项);
您可以删除options参数,因为您没有配置它。
cosmosContainer.deleteItem(“”,新的PartitionKey());