SQL 通过整数查询 Azure Functions 中的 DocumentDB 无效

SQL Query DocumentDB in Azure Functions by an integer not working

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

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

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

{
    "randomId": 1,
    "partitionKey": "prospect"
}

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

如果我用 random 向我的 collection 添加值 "1" 的东西,以下将起作用:

{
    "randomId": "1",
    "partitionKey": "prospect"
}

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

有什么解决办法吗?

编辑:

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

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

SELECT * FROM c where c.random = udf.ConvertToNumber({randomId})