[英]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.