当前位置: 首页 > 知识库问答 >
问题:

Azure Cosmos Bulk-Executor库- {\ "错误\":[\ "输入内容无效,因为必需的属性-' id;'-缺少\"]}

沈树
2023-03-14

我正在尝试使用Azure批量执行器库批量插入文档/Json。我使用了Azure文档中描述的方法:https://docs.microsoft.com/en-us/azure/cosmos-db/bulk-executor-java

下面是DocumentClient的创建:

  public static DocumentClient documentClientFrom(BulkExecutionConfiguration cfg) throws DocumentClientException {
    
    ConnectionPolicy policy = new ConnectionPolicy();
    RetryOptions retryOptions = new RetryOptions();
    retryOptions.setMaxRetryAttemptsOnThrottledRequests(0);
    policy.setRetryOptions(retryOptions);
    policy.setConnectionMode(cfg.getConnectionMode());
    policy.setMaxPoolSize(cfg.getMaxConnectionPoolSize());
    
    return new DocumentClient(cfg.getServiceEndpoint(), cfg.getMasterKey(), policy, cfg.getConsistencyLevel());
}

当我尝试进行如下批量导入时:

BulkImportResponse bulkImportResponse = bulkExecutor.importAll( documents, false, true, null );

我得到了错误:

com.microsoft.azure.documentdb.DocumentClientException: Message: {"Errors":["Encountered exception 
while executing function. Exception = Error: {\"Errors\":[\"The input content is invalid because the 
required properties - 'id; ' - are missing\"]}\r\nStack trace: Error: {\"Errors\":[\"The input 
content is invalid because the required properties - 'id; ' - are missing\"]}\n   at createCallback 
(script.js:6223:26)\n   at Anonymous function (script.js:686:29)"]}
ActivityId: 3b6ca789-508d-40a2-bda1-b4e424dac88f, Request URI: /apps/6ec7164c-b528-494b-b40e- 
249832f34bb1/services/221058a8-0299-4341-ad5a-0ea3d0a49cc1/partitions/ebae0619-6126-453c-b6a1- 
774739a52a71/replicas/132378420031633670p/, RequestStats: 
RequestStartTime: 2020-07-08T10:55:11.7899079Z, RequestEndTime: 2020-07-08T10:55:11.7999008Z,  Number 
of regions attempted:1
ResponseTime: 2020-07-08T10:55:11.7999008Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod- 
southcentralus1-fd11.documents.azure.com:14397/apps/6ec7164c-b528-494b-b40e- 
249832f34bb1/services/221058a8-0299-4341-ad5a-0ea3d0a49cc1/partitions/ebae0619-6126-453c-b6a1- 
774739a52a71/replicas/132378420031633670p/, LSN: 105, GlobalCommittedLsn: 105, PartitionKeyRangeId: 
0, IsValid: True, StatusCode: 400, SubStatusCode: 400, RequestCharge: 4.38, ItemLSN: -1, 
SessionToken: -1#105, UsingLocalLSN: False, TransportException: null, ResourceType: StoredProcedure, 
OperationType: ExecuteJavaScript
, SDK: Microsoft.Azure.Documents.Common/2.11.0, StatusCode: BadRequest
at com.microsoft.azure.documentdb.internal.ErrorUtils.maybeThrowException(ErrorUtils.java:74)
at com.microsoft.azure.documentdb.internal.GatewayProxy.performPostRequest(GatewayProxy.java:284)
at com.microsoft.azure.documentdb.internal.GatewayProxy.doExecute(GatewayProxy.java:108)
at com.microsoft.azure.documentdb.internal.GatewayProxy.processMessage(GatewayProxy.java:360)
at com.microsoft.azure.documentdb.DocumentClient$5.apply(DocumentClient.java:3037)
at com.microsoft.azure.documentdb.internal.RetryUtility.executeDocumentClientRequest(RetryUtility.java:73)
at com.microsoft.azure.documentdb.DocumentClient.doCreate(DocumentClient.java:3042)
at com.microsoft.azure.documentdb.DocumentClient.executeStoredProcedure(DocumentClient.java:1571)
at com.microsoft.azure.documentdb.bulkexecutor.internal.BatchInserter$1.call(BatchInserter.java:186)
at com.microsoft.azure.documentdb.bulkexecutor.internal.BatchInserter$1.call(BatchInserter.java:158)
at com.microsoft.azure.documentdb.repackaged.com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
at com.microsoft.azure.documentdb.repackaged.com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:57)
at com.microsoft.azure.documentdb.repackaged.com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

这是我试图插入的对象的json:

.........

"grocinvoiceInd": "N",
"_id": {
    "transactionId": {
        "$numberLong": "<xxxxxx>"
    },
    "txnSeqNbr": 0
},
"sourceInfo": "<xxxxxxx>"
}

显然,它看起来有一个_id字段,但它没有插入记录。非常感谢任何帮助。

共有1个答案

商皓
2023-03-14

文档必须有一个id字段,因为您使用分区键创建了一个集合,如果您使用分区键创建一个集合,则该集合中的所有文档都必须具有该属性

https://docs . Microsoft . com/en-us/azure/cosmos-db/partitioning-overview

此外,如 Azure 文档 https://docs.microsoft.com/en-us/azure/cosmos-db/bulk-executor-java 所述,“目前,批量执行程序库仅受 Azure Cosmos DB SQL API 和 Gremlin API 帐户支持。考虑到这一点,我们批量执行器目前可能无法使用MongoDB存储帐户。

 类似资料:
  • 我创建了一个这样的xml文件: 和活动: 如你所见,我什么也没做。但是我得到了一个错误: 您的内容必须具有id属性为“android.R.id.list”的ListView 即使我的xml中有行。 有什么问题?

  • 为什么验证器(http://validator.w3.org/)拒绝这个?什么属性是我不知道的“必需”? 错误: 错误行408,第142列:元素链接缺少必需的属性/模块/14ce1e21/peadig eucookie。css'type='text/css'media='all'/

  • 这是我的。工作文件 作业失败,出现以下错误: 我用的是Azkaban 2.5和cdh5

  • 问题内容: 将JSON数据从JSP传递到ResponseBody中的控制器时出错。 Ajax电话: 控制器: AppConfig.java @豆 请帮助我摆脱困境。我正在使用Spring 4,Jakson 2.3.0 如果我尝试POST请求,它将给出:org.springframework.web.HttpRequestMethodNotSupportedException:请求方法’POST’不

  • 问题内容: 我正在使用Eclipse for Java Develepers(在Windows 7上运行的Juno x64)。 我有一个项目正在尝试不再需要的jar(args4j),因此删除了依赖项。在某个时候,我的PC意外断电,从那以后,我重新启动了Eclipse。 我的项目现在有一个错误。在删除依赖项而没有任何问题之后,我在该项目上工作了一段时间。 在“项目属性”>“ Java构建路径”下,任

  • 问题内容: 我只是想知道如何以正确的方式在单选按钮上使用新的HTML5输入属性“ required”。是否每个单选按钮字段都需要下面的属性,或者只有一个字段就足够了吗? 问题答案: 为无线电组的至少一个输入设置属性。 所有输入的设置更加清晰,但不是必需的(除非动态生成单选按钮)。 要对单选按钮进行分组,它们必须全部具有相同的值。这样一次只能选择一个,并应用于整个组。 另请注意: 为了避免对是否需要