首页 > 解决方案 > Azure Cosmos DB 输入绑定 - 不能将 OFFSET 和 LIMIT 值作为参数传递?

问题描述

我在尝试将查询参数的值动态传递给我的 CosmosDB 触发器时遇到OFFSET问题LIMIT

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

但是,使用此代码:

 {
      "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 });
}

标签: azureazure-functionsazure-cosmosdb

解决方案


推荐阅读