Saya mencoba memasukkan dokumen/Json secara massal menggunakan perpustakaan Azure Massal Executor. Saya menggunakan pendekatan seperti yang dijelaskan dalam Dokumentasi Azure di sini: https ://docs.microsoft.com/en-us/azure/cosmos-db/bulk-executor-java

Di bawah ini adalah pembuatan 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());
}

Ketika saya mencoba melakukan impor massal seperti di bawah ini:

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

Saya mendapatkan Kesalahan:

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)

Ini json untuk objek yang saya coba masukkan:

.........

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

Rupanya sepertinya memiliki bidang _id tetapi tidak memasukkan catatan. Bantuan apa pun sangat dihargai.

0
Zubair 9 Juli 2020, 09:57

1 menjawab

Jawaban Terbaik

Dokumen harus memiliki bidang id, karena Anda telah membuat koleksi dengan kunci partisi, jika Anda membuat koleksi dengan kunci partisi, semua dokumen dalam koleksi itu harus memiliki properti itu

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

Juga seperti yang dijelaskan dalam dokumentasi Azure https://docs. microsoft.com/en-us/azure/cosmos-db/bulk-executor-java "Saat ini, perpustakaan pelaksana massal hanya didukung oleh Azure Cosmos DB SQL API dan akun API Gremlin." Mempertimbangkan ini, kami pelaksana massal mungkin tidak bekerja dengan akun penyimpanan MongoDB saat ini.

1
Zubair 14 Juli 2020, 06:59