【发布时间】:2019-05-13 20:20:10
【问题描述】:
我创建了一个通过 HTTP POST 请求触发的 Azure 函数。
该请求的正文如下:
{
"start": '2018-07-25T08:47:16.094Z',
"end": '2018-07-25T08:47:24.686Z'
}
index.js
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var inputDocument = context.bindings.inputDocument;
context.log("INPUT DOCUMENT: " + JSON.stringify(inputDocument));
context.res = {
status: 200,
body: "OK",
};
};
function.json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "cosmosDB",
"name": "inputDocument",
"databaseName": "Messages",
"collectionName": "Collection1",
"sqlQuery": "SELECT * FROM Collection1 c WHERE c.message.timestamp>={start} AND c.message.timestamp<={end}",
"connectionStringSetting": "cosmosdbaccount_DOCUMENTDB",
"direction": "in"
}
]
}
我想使用以下两个参数查询 CosmosDB 实例:
"sqlQuery": "SELECT * FROM Collection1 c WHERE c.message.timestamp>={start} AND c.message.timestamp<={end}",
像我在这里展示的那样做会导致 CosmosDB 的 inputBinding 未定义。
2018-12-13T08:19:54.332 [Information] Executing 'Functions.Function1' (Reason='This function was programmatically called via the host APIs.', Id=af8090a4-5fab-4fbd-b26f-a045d8900d9b)
2018-12-13T08:19:56.704 [Information] JavaScript HTTP trigger function processed a request.
2018-12-13T08:19:56.711 [Information] INPUT DOCUMENT: []
2018-12-13T08:19:56.755 [Information] Executed 'Functions.Function1' (Succeeded, Id=af8090a4-5fab-4fbd-b26f-a045d8900d9b)
如果我在 CosmosDB 数据资源管理器中运行相同的查询,用正确的 ISO 时间戳替换 start 和 end,它会返回所有四个文档。
我错过了什么吗?我真的没有在网上找到任何关于这个话题的东西,所以我希望有人已经偶然发现了它。
提前非常感谢!
【问题讨论】:
标签: azure azure-functions azure-cosmosdb