本文介绍了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查询:

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通过整数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 11:54