Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Query DocumentDB in Azure Functions by an integer not working

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:

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"
}

With this, I get no results. I've definitely verified that I have one object with random having a value of 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"
}

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?

EDIT:

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

like image 611
Jack Musick Avatar asked Oct 18 '22 08:10

Jack Musick


1 Answers

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})
like image 67
Aaron Chen Avatar answered Oct 19 '22 22:10

Aaron Chen