参考此azure documentation 这个using parameters from http trigger
具体指
"id" : "{queueTrigger_payload_property}",
"partitionKey": "{queueTrigger_payload_property}",
如果我有一个javascript函数,http Trigger在正文中提供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 Trigger在函数中看起来像这样:req.body.thingid
,但是对输入的绑定会导致错误,“属性未定义”,所以如何使用HTTP Trigger输入来获取从第一个输入中的json数据包到查询cosmos db的值,都在同一个函数中?
答案 0 :(得分:3)
应该只是{thingid}
:
{
"type": "documentDB",
"name": "inputDocument",
"databaseName": "mydb",
"collectionName": "things",
"connection": "my_DOCUMENTDB",
"direction": "in",
"sqlQuery": "select * from things s where s.thingid={thingid}"
}
对于像
这样的POST请求{
"thingid": "293a2fc3-799f-4669-92d3-3413f1afa51e"
}
它将以context.bindings.inputDocument
(javascript数组)传递文档。