Azure Cosmos DB输入绑定-无法将OFFSET和LIMIT值作为参数传递?

时间:2019-07-29 13:05:13

标签: azure azure-functions azure-cosmosdb

我在尝试将OFFSETLIMIT的值作为查询参数动态传递到CosmosDB触发器时遇到问题。

如果我将这两个值硬编码到查询中,它将按预期工作。

但是,使用以下代码:

 {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "route": "v1/query/properties",
      "methods": [
        "post"
      ]
    },
    {
      "name": "propertiesInquiryInput",
      "type": "cosmosDB",
      "databaseName": "property",
      "collectionName": "discovery",
      "connectionStringSetting": "CosmosDBConnectionString",
      "direction": "in",
      "leaseCollectionName": "leases",
      "sqlQuery": "SELECT * FROM c WHERE c.country={country} OFFSET {pageNo} LIMIT {perPage}"
    },

执行时出现以下错误:

System.Private.CoreLib: Exception while executing function: Functions.queryProperties. Microsoft.Azure.DocumentDB.Core: Message: {"errors":[{"severity":"Error","location":

{"start":48,"end":55},"code":"SC2062","message":"The OFFSET count value exceeds the maximum allowed value."},
{"severity":"Error","location":{"start":62,"end":70},"code":"SC2061","message":"The LIMIT count value exceeds the maximum allowed value."}]}

我对Azure服务及其模式还比较陌生,所以也许我在这里遗漏了一些明显的东西。我尝试通过POST将这些值作为JSON对象发送,并通过GET请求作为查询参数发送。似乎没有任何作用。

我也不知道一种方法来查看正在触发的SQL查询,以便从那个角度调试它。朝正确方向的任何指导将不胜感激。

更新:

为清楚起见添加功能主体:

module.exports = async function (context, req) {
    const results = context.bindings.propertiesInquiryInput;
    !results.length && context.done(null, { status: 404, body: "[]", });

    const body = JSON.stringify(results.map(data => reshapeResponse(data));

    return context.done(null, { status: 200, body });
}

0 个答案:

没有答案