我已经为bulkInsert编写了存储过程,我也在这里处理SP的超时。在执行SP时,我仍然会得到“请求大小太大”的异常。给予低于SP。请帮帮我,我错了。我只从pluralsight取了所有密码。以和他们一样的方式处理。
function spBulkInsert(docs){
if (!docs) {
throw new Error('Documents array is null or not defined!');
}
var context = getContext();
var collection = context.getCollection();
var response = context.getResponse();
var docCount = docs.length;
if (docCount == 0) {
response.setBody(0);
return;
}
var count = 0;
createDoc(docs[0]);
function createDoc(doc) {
var isAccepted = collection.createDoucument(collection.getSelfLink(), doc, docCreated);
if (!isAccepted) {
response.setBody(count);
}
}
function docCreated(err, doc) {
if (err) throw err;
count++;
if (count == docCount) response.setBody(count);
else createDoc(docs[count]);
}
};以上SP处理代码:
var totalInsertedCount=0;
while (totalInsertedCount < data.Count)
{
var insertedCount = await client.ExecuteStoredProcedureAsync<int>(
UriFactory.CreateStoredProcedureUri("TestDoc", "coll", "spBulkInsert"),
new RequestOptions { PartitionKey = new PartitionKey("partitionKey") }, data);
totalInsertedCount += insertedCount;
Console.WriteLine("Inserted {0} documents ({1} total, {2} remaining)", insertedCount, totalInsertedCount, data.Count - totalInsertedCount);
data= data.GetRange(insertedCount, data.Count - insertedCount);
}发布于 2017-09-15 03:01:51
作为总结,The document size in the request exceeded the allowable document size for a request. The max allowable document size is 2MB.提到了这里。
Stored Procedure Bulk importing data是一个执行存储过程的过程,只有一个HTTP请求,每个HTTP请求所请求的文档的大小受到2MB下面的Cosmos DB的限制。
建议
1.您可以将文档数据拆分并分批导入。
2.您可以尝试简化文档数据,例如删除不必要的“”和“\n”等。
发布于 2017-09-14 20:12:55
不管写在哪里(SP、API或门户),Cosmos DB中的文档大小总是有2MB的限制。在向Cosmos DB提交之前,必须在客户端拆分/卸载/链接/链接/等文档。
https://stackoverflow.com/questions/46200022
复制相似问题