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.
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})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With