首页 文章

azure函数http触发器输入cosmos db文件

提问于
浏览
1

参考这个azure documentation和_1111415_

它具体指的是

"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 ,但是绑定到输入会导致错误,"property not defined"所以我如何使用HTTP Trigger输入从json数据包获取值来查询cosmos db in第一个输入,都在同一个功能?

1 回答

  • 2

    它应该只是 {thingid}

    {
      "type": "documentDB",
      "name": "inputDocument",
      "databaseName": "mydb",
      "collectionName": "things",
      "connection": "my_DOCUMENTDB",
      "direction": "in",
      "sqlQuery": "select * from things s where s.thingid={thingid}"
    }
    

    对于像POST这样的POST请求

    {
      "thingid": "293a2fc3-799f-4669-92d3-3413f1afa51e"
    }
    

    它将在 context.bindings.inputDocument (javascript数组)中传递文档 .

相关问题