Azure Functions 中的 SQL Query DocumentDB 按整数不起作用

Jac*_*ick 5 javascript azure node.js azure-functions azure-cosmosdb

我在 Azure Functions 中使用 JavaScript 语言。使用 Cosmos DB 作为输入时,我无法将整数作为变量进行查询。例如,我有以下内容:

使用 Azure Cosmos DB 作为我的输入(公司)的函数设置。这是使用分区键作为{partitionKey}和我的 SQL 查询作为设置SELECT * FROM c where c.random = {randomId}

在函数的代码中,我发送了以下内容作为我的测试数据:

{
    "randomId": 1,
    "partitionKey": "prospect"
}
Run Code Online (Sandbox Code Playgroud)

有了这个,我没有得到任何结果。我已经确定我有一个random值为 1 的对象。

如果我要向我的收藏中添加random值为 的内容"1",则以下操作将起作用:

{
    "randomId": "1",
    "partitionKey": "prospect"
}
Run Code Online (Sandbox Code Playgroud)

我已经在 DocumentDB API 和 MongoDB API 上尝试过这个,这应该无关紧要,因为绑定内置于 Azure Functions 中。我在不同数据集上看到的趋势是,当您将整数参数绑定到查询或文档 ID 字段中的某些内容时,查询将不起作用。

任何想法如何解决这一问题?

编辑:

我已经通过可用文档确认这在 C# 中有效。

Aar*_*hen 3

参考Amor对类似问题的回答。首先,您可以按照此答案中的步骤创建 UDF 以将字符串值转换为整数。然后更改 SQL 查询如下:

SELECT * FROM c where c.random = udf.ConvertToNumber({randomId})
Run Code Online (Sandbox Code Playgroud)