使用Mongo API在Azure Cosmos DB上执行存储过程后,Mongo Collection已损坏。 这是存储过程的主体:
function bulkImport(docs) {
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var count = 0;
if (!docs) throw new Error("The array is undefined or null.");
var docsLength = docs.length;
if (docsLength == 0) {
getContext().getResponse().setBody(0);
}
tryCreate(docs[count], callback);
function tryCreate(doc, callback) {
var options = {
disableAutomaticIdGeneration: true
};
var isAccepted = collection.createDocument(collectionLink, doc, options, callback);
if (!isAccepted) getContext().getResponse().setBody(count);
}
function callback(err, doc, options) {
if (err) throw err;
count++;
if (count >= docsLength) {
getContext().getResponse().setBody(count);
} else {
tryCreate(docs[count], callback);
}
}
}
此处直接在Cosmos DB数据资源管理器中执行存储过程。 输入:[{'type':'A','name':'test'}]。
答案 0 :(得分:0)
我注意到您将disableAutomaticIdGeneration
设置为true
,并且您未在输入"id"
中提供[{ 'type': 'A', 'name':'test' }]
属性。这将导致异常。
您可以将disableAutomaticIdGeneration
设置为false
,或者在输入中提供"id"
属性,然后就可以了。
希望它对你有所帮助。
答案 1 :(得分:0)
这是我从Azure支持中听到的:
触发器,UDF是通过我们的SQL API公开的功能。 #CosmosDB的MongoDB API使用MongoDB可编程性表面区域 - 它不使用sprocs,trigger,UDF的概念。请通过AskCosmosDB@microsoft.com与我们联系,我们将为您提供帮助。