首页 文章

Azure documentDB - 已存在具有指定标识或名称的资源

提问于
浏览
2

在我的应用程序中的Azure Cosmo DocumentDB中,我收到了以下错误

2018-03-27 14:42:057错误c.h.m.s.CosmosDBFruiteService - 无法将Fruites添加到客户参考:11416e34-3620-45a4-b3be-b845bbf41762
Message: {"Errors":["Resource with specified id or name already exists."]} ActivityId:1b70b944-d581-4640-8785-819400433bb4,请求URI:/ apps / 8d13f597-c7e4-4d60-8713-8a0e9abaa9ac / services / ce0d287f-0125-482b-b32c-22108b5b0ed3 / partitions / 42c80a49-8042-4032-8cfd -9937ecea8dcc / replicas / 131662740073245648p,RequestStats :,SDK:Microsoft.Azure.Documents.Common / 1.21.0.0,StatusCode:Conflict 2018-03-27 14:42:058 ERROR chmaeGlobalExceptionHandler - 异常:class org.apache.catalina . connector.ClientAbortException消息:java.io.IOException:远程主机强制关闭现有连接2018-03-27 14:42:058 WARN oswsmmaExceptionHandlerExceptionResolver - 无法调用@ExceptionHandler方法:public java.util.Map com . hm.myfeed.api.exception.GlobalExceptionHandler.handleException(java.lang.Exception,org.springframework.web.context.request.WebRequest,javax.servlet.http.HttpServletRequest)org.apache.catalina.connector.ClientAbortException:java . io.IOException:远程主机a强制关闭现有连接org.apache.catalina.connector.OutputBuffer.append上的org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:815)中的org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:356) (outputBuffer.java:720)org.apache中的org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:391)org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:369) . catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96)at org.springframework.security.web.util.OnCommittedResponseWrapper $ SaveContextServletOutputStream.write(OnCommittedResponseWrapper.java:639)

我不明白这一点 . 代码中出现异常,首先检查集合是否存在(确实存在)然后如果它没有创建它 . 很明显,创建将失败,集合存在!

Create function

try { fruitesDocument = documentClient.createDocument(getCollectionLink(), fruitesDocument , null, false).getResource(); } catch (DocumentClientException e) { LOG.error("Could not add fruites to Customer Reference : " + fruitesModel.getId() + " " + e .getMessage()); }

Update Function :

try { fruitesDocument = documentClient.replaceDocument(fruitesDocument , null).getResource(); } catch (DocumentClientException e) { LOG.error("Error while updating fruites: " + e.getMessage()); }

在创建文档时遇到问题 .

1 回答

  • 1

    使用 DocumentClient.UpsertDocumentAsync 而不是documentClient.replaceDocumentAsync

    如果文档尚不存在,Upsert将创建一个文档,否则将覆盖它 . 替换要求文档已存在,然后覆盖它 . 使用哪个是您的应用程序的问题 .

相关问题