【发布时间】:2018-07-15 02:33:42
【问题描述】:
参考这个azure documentation 还有这个using parameters from http trigger
特指
"id" : "{queueTrigger_payload_property}",
"partitionKey": "{queueTrigger_payload_property}",
如果我有一个 javascript 函数,一个 http 触发器,它在正文中提供一个 JSON 数据包。如何使用 Azure cosmos db 绑定获取文档,使用绑定将 http json 值传递给 cosmos db 查询?
我希望与此类似:
"sqlQuery": "SELECT * from c where c.departmentId = {departmentId}",
除了{departmentId} 应该是来自httptrigger 的属性(命名为req)?
因此 function.json 看起来像这样:
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req"
}, {
"type": "documentDB",
"name": "inputDocument",
"databaseName": "mydb",
"collectionName": "things",
"partitionKey": "/things/thingid",
"connection": "my_DOCUMENTDB",
"direction": "in",
"sqlQuery": "Select * from things s where s.thingid={httpTrigger_body_thingid}"
}
javascript 中的 http 触发器在函数中看起来像这样,它可以工作:req.body.thingid,但是绑定到输入会导致错误,“未定义属性”所以我如何使用 HTTP 触发器输入来获取值从一个json数据包到第一个输入中查询cosmos db,都在同一个函数中?
【问题讨论】:
标签: javascript azure-cosmosdb azure-functions