Azure函数JavaScript function.json使用浮点数进行路由数据绑定

Azure函数JavaScript function.json使用浮点数进行路由数据绑定,azure,azure-functions,Azure,Azure Functions,我正在尝试使用JavaScript Azure函数数据绑定到Cosmos DB,使用where子句中带有浮点参数的sqlQuery 以下是我在function.json中的绑定定义: 不起作用,我认为不会返回任何结果,因为lat/lon被视为字符串: "bindings": [ { "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "r

我正在尝试使用JavaScript Azure函数数据绑定到Cosmos DB,使用where子句中带有浮点参数的sqlQuery

以下是我在function.json中的绑定定义:

不起作用,我认为不会返回任何结果,因为lat/lon被视为字符串:

  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "route": "GetLoq/{lat:float}/{lon:float}"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "cosmosDB",
      "name": "doc",
      "databaseName": "%CosmosDBNAME%",
      "collectionName": "%CosmosCollectionNAME%",
      "sqlQuery": "SELECT * FROM c where c.location.coordinates = [{lat}, {lon}]",
      "connectionStringSetting": "DB",
      "direction": "in"
    }
  ]
在硬编码值(用于比较)时工作:


查询不起作用,因为它搜索的是字符串值
[“36.71”,“3.25”]
,而不是float

还有一个问题尚未解决

路由约束允许为HttpTrigger路由属性上的查询字符串参数指定数据类型。这些约束仅用于匹配管线。 使用绑定参数时,数据类型将转换为字符串

我们必须先创建一个UDF
toFloat
(单击集合>新建UDF旁边的更多选项图标)将字符串转换为float

function stringToFloatUDF(input){
    return parseFloat(input);
}
然后使用UDF修改sqlQuery

"sqlQuery": "SELECT * from c where c.location.coordinates = [udf.toFloat({lat}), udf.toFloat({lon})]",
"sqlQuery": "SELECT * from c where c.location.coordinates = [udf.toFloat({lat}), udf.toFloat({lon})]",