简体   繁体   English

如何在Azure表存储中查找与值数组不匹配的记录?

[英]How do I find records in Azure table storage that don't match an array of values?

I'm trying to perform a 'doesNotContainAllObjectsInArray' type operation on Azure Mobile Services. 我正在尝试在Azure移动服务上执行'doesNotContainAllObjectsInArray'类型的操作。 For example, let's say I have a table called Number and within that table are these records with these 'number' values: 11111, 22222, 33333, 44444. 例如,假设我有一个名为Number的表,并且该表中的这些记录具有以下“ number”值:11111、22222、33333、44444。

I want to be able to write a query that will allow me to pass in an array of numbers that I specifically don't want, for example: [11111,44444] should yield me with [22222, 33333] . 我希望能够编写一个查询,使我可以传递我明确不希望的数字数组,例如: [11111,44444]应该让我得到[11111,44444] [22222, 33333]

I've tried using JavaScript in my where operator, but I'm getting an error back stating that the expression isn't supported. 我曾尝试在where运算符中使用JavaScript,但是却收到一条错误消息,指出不支持该表达式。 This is what I've tried: 这是我尝试过的:

var numberTable = tables.getTable('Number');
var ignoreNumbers = ['11111', '44444'];
numberTable.where(function(numbers) {
    return (numbers.indexOf(this.number) > -1);
}, ignoreNumbers).read({
    success: function(foundNumbers) {
        console.log('Found ' + foundNumbers.length + ' numbers!');
    },
    error: function(error) {
        console.error('Error with query! ' + error);
    }
});

Note: I can't hard code the ignoreNumbers values, since that array is produced from a previous query. 注意:由于该数组是从先前的查询生成的,因此我无法对ignoreNumbers值进行硬编码。

Can anyone recommend how I might go about executing a query like this? 谁能建议我如何执行这样的查询? Would I need build a SQL statement and execute it with mssql ? 我需要构建一个SQL语句并使用mssql执行它吗? (...is that even possible with Table Storage?) (...表存储甚至有可能吗?)

You are describing the SQL Except operator which isn't supported in Table Queries . 您正在描述表查询中不支持的SQL Except运算符。 The only way I've found to do this is to load the table into memory (often not feasible due to size) and then use LINQ to do an Except query. 我发现这样做的唯一方法是将表加载到内存中(由于大小而通常不可行),然后使用LINQ进行Except查询。

I managed to solve this by creating a SQL query and executing it through the request.service.mssql object, something like this: 我设法通过创建SQL查询并通过request.service.mssql对象执行该查询来解决此问题,如下所示:

SELECT * FROM Number WHERE (number != '11111' && number != '22222')

The WHERE part of the query is built by iterating the ignoreNumbers array and building the SQL statement by string concatenation. 查询的WHERE部分是通过迭代ignoreNumbers数组并通过字符串连接构建SQL语句而构建的。

Not sure if it's the most efficient thing in the world, but in reality there are only going to be a couple of numbers (maybe 5-10) and so far it seems to work. 不确定这是否是世界上最有效的方法,但实际上只有几个数字(可能是5-10),到目前为止看来还是可行的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的循环没有分隔与另一个数组不匹配的数组项,我该怎么做? - My loop isn't separating the array items that don't match on the other array, how can I do that? 我不知道如何打印数组的所有值 - I don't know how to print all the values ​of an array 我该如何编写此RegEx来匹配给定的测试用例? (不匹配结束时间) - How do I need to write this RegEx to match the given test case? (don't match the ending period) 如何避免遍历数组以查找部分匹配项? - How do I avoid looping through an array to find a partial match? 如何在 JavaScript 中的数组中找到精确匹配的 substring? - How do I find an exact substring match in an array in JavaScript? 在续集中,如何选择与多行的不同值匹配的记录? - In sequelize, how do I select records that match different values of multiple rows? 如何在2个数组不匹配的索引上输入空值? - How can I enter null values on indexes where 2 arrays don't match? JavaScript:如何对字典中的值进行排序以输出匹配的值并输出不匹配的值显示空结果 - JavaScript : How can I sort values in a dictionary to output matched values and ouput the values that don't match showing an empty result 如何用 jest 模拟 azure-storage 表服务功能? - How do I mock azure-storage table service functionality with jest? 如何使用正则表达式来匹配不包含某些子字符串的字符串? - How do I use regex to match strings that don't contain certain substrings?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM