通过整数在 Azure Functions 中 SQL 查询 DocumentDB 不起作用

2023-08-02前端开发问题
1

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

The End

相关推荐

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

JavaScript(js)文件字符串中丢失"\"斜线的解决方法
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转...
2024-10-17 前端开发问题
437

layui中table列表 增加属性 edit="date",不生效怎么办?
如果你想在 layui 的 table 列表中增加 edit=date 属性但不生效,可能是以下问题导致的: 1. 缺少日期组件的初始化 如果想在表格中使用日期组件,需要在页面中引入 layui 的日期组件,并初始化: script type="text/javascript" src="/layui/layui.js"/scrip...
2024-06-11 前端开发问题
455

Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)...
2024-04-20 前端开发问题
5

CoffeeScript 总是以匿名函数返回
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)...
2024-04-20 前端开发问题
13