0

There are a lot of examples circulating around the internet about how you can use CompareTo with Azure Table Storage to basically do some substring searching from C# , but I can't find anything showing how to do it in NodeJS and all the syntaxes I've tried to put together just throw back various syntax or invalid query storage exceptions.

Can anyone tell me how to do the equivalent of the C# example on this website, but from NodeJS? https://lifeportal.azurewebsites.net/azure-table-storage-searching-entities-using-query-like-substring-or-left/

string projectIdString = projectId.ToString().ToLower(); // projectId - Guid
string startQuery = projectIdString + "_"; // Our separate symbol
string endQuery = projectIdString + "`"; // Next symbol in ASCII table after "_"

Expression<Func<DynamicTableEntity, bool>> filters = (e.RowKey.CompareTo(startQuery) >= 0 && e.RowKey.CompareTo(endQuery) < 0);
CloudTable table = _storageContext.Table(Tables.Users);

bool result = await DeleteAllEntitiesInBatches(table, filters);
return result;

What seems like the most obvious of:

const TABLE_NAME = 'MYTABLE';

var azure = require('azure-storage');
var tableService = azure.createTableService();
var query = new azure.TableQuery()
    .where('PartitionKey eq ?', 'MYKEY').and('RowKey.compareTo(\'1-\') ge ?', 0);

tableService.queryEntities(TABLE_NAME, query, null, function(error, result, response) {
    if (!error) {
        // result.entries contains entities matching the query
    }
});

Results in:

"An unknown function with name 'RowKey.compareTo' was found. This may also be a key lookup on a navigation property, which is not allowed."
Doug
  • 6,446
  • 9
  • 74
  • 107

1 Answers1

1

It looks like you are attempting to query RowKey with a StartsWith. In node.js you can use operator ge (greater than or equal) to do that.

So your code would be something like:

var query = new azure.TableQuery()
    .where('PartitionKey eq ?', 'MYKEY').and('RowKey ge ?', '<starts with substring>');
Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
  • Thank-you. I don't know why I didn't see this. It seems so obvious now that you replied. – Doug Mar 27 '17 at 14:06
  • I may have spoke too soon. That is not correct, I am not trying to do startsWith, startsWith is straight forward. When I have a compound key: KEY1_KEY2, I want to be able to search off of the KEY2 values. That is my understanding of what the link I referenced with the CompareTo did. Is there the CompareTo equiv from NodeJS? – Doug Mar 28 '17 at 17:16
  • Arg, maybe I misread that example in the first place. It looks like it does LEFT (aka startsWith) – Doug Mar 28 '17 at 17:19
  • Unfortunately, Azure Table Storage doesn't support wildcard searching, such as `endsWith`, and `contains` query. – Aaron Chen Mar 29 '17 at 02:22