【问题标题】:Stored Procedure in MongoDB API: Azure Cosmos DBMongoDB API 中的存储过程:Azure Cosmos DB
【发布时间】:2018-05-12 18:51:45
【问题描述】:

使用 Mongo API 在 Azure Cosmos DB 上执行存储过程后,Mongo 集合已损坏。 这是存储过程的主体:

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' }].

【问题讨论】:

    标签: azure-cosmosdb azure-cosmosdb-mongoapi


    【解决方案1】:

    我注意到您将disableAutomaticIdGeneration 设置为true,并且您没有在输入[{ 'type': 'A', 'name':'test' }] 中提供"id" 属性。这会导致异常。

    您可以将disableAutomaticIdGeneration 设置为false,或者您在输入中提供"id" 属性并且它可以工作。

    希望对你有帮助。

    【讨论】:

    • 我尝试提供 id,但没有成功。我尝试将'disableAutomaticIdGeneration'设置为false,它也不起作用。
    【解决方案2】:

    这是我从 Azure 支持人员那里听到的:

    触发器和 UDF 是通过我们的 SQL API 公开的功能。 #CosmosDB 的 MongoDB API 使用 MongoDB 可编程表面积——它不使用存储过程、触发器、UDF 的概念。请通过 AskCosmosDB@microsoft.com 与我们联系,我们将为您提供帮助。

    【讨论】:

      猜你喜欢
      • 2019-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 1970-01-01
      • 2018-04-10
      • 2021-11-14
      相关资源
      最近更新 更多