azure - 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 });
}
解决方案
推荐阅读
- vue.js - 是否建议将仅由一个组件使用的 Vue 组件的方法提取到 Vue mixin 中?
- google-apps-script - 如何仅从文件夹中列出电子表格或将文件对象转换为电子表格对象
- wordpress - 如何使用 JQuery 以编程方式将标签添加到 WordPress Gutenberg
- html - 在 for 循环中使用折叠引导 django
- javascript - 如何在邮递员中使用 javascript 将唯一对象添加到 json 数组
- python-3.x - 如何从表中提取上下文数据来训练自定义命名实体识别器?
- verilog - Verilog中特定整数计数的位数
- linux - 如何在 docker 中运行本地图像/容器?
- typescript - Typescript - 如何将函数指针传递给函数并在函数体内调用
- blockchain - 关于区块链和智能合约的几个问题