通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用 [英] SQL Query DocumentDB in Azure Functions by an integer not working

查看:28
本文介绍了通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the JavaScript language in Azure Functions. When using Cosmos DB as the input, I cannot query by an integer as a variable. For example, I have the following:

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

Function setup with Azure Cosmos DB as my input (companies). This is setup with the partition key as {partitionKey} and my SQL Query as SELECT * FROM c where c.random = {randomId}.

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

In the function's code, I've sent the following as my test data:

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

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

With this, I get no results. I've definitely verified that I have one object with random having a value of 1.

如果我要使用 random 向我的集合中添加一些值为 "1" 的内容,则可以使用以下方法:

If I were to add something to my collection with random with a value of "1", the following would work:

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

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

I've tried this with both the DocumentDB API and MongoDB API, which shouldn't matter since the binding is built into Azure Functions. The trend I've seen with different sets of data is that querying just doesn't work when you bind a integer parameter to something in the query or Document ID field.

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

Any ideas how to fix this?

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

I've confirmed this works in C# with the available documentation.

推荐答案

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

Refer to Amor's answer to a similar question. First, you can follow the steps in this answer to create a UDF to convert a string value to an integer. Then change the SQL Query as below:

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

这篇关于通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆