代码之家  ›  专栏  ›  技术社区  ›  Cloud guy

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

  •  2
  • Cloud guy  · 技术社区  · 7 年前

    参考此 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 (命名请求)?

    因此,功能。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 然而,绑定到输入会导致错误,“property not defined”,那么如何使用HTTP触发器输入从json数据包中获取一个值,以便在第一个输入中查询cosmos db,所有这些都在同一个函数中?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Mikhail Shilkov    7 年前

    应该是 {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数组)。