互联网上有很多关于如何将CompareTo与Azure表存储结合使用以基本上从C#进行子字符串搜索的示例 ,但我找不到任何显示如何在NodeJS中执行此操作的内容以及我尝试放在一起的所有语法只会丢弃各种语法或无效的查询存储异常。
有谁能告诉我如何在这个网站上做同样的C#示例,但是来自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;
看起来最明显的是:
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
}
});
结果:
"An unknown function with name 'RowKey.compareTo' was found. This may also be a key lookup on a navigation property, which is not allowed."
答案 0 :(得分:1)
您似乎正在尝试使用StartsWith
查询RowKey。在node.js中,您可以使用运算符ge
(大于或等于)来执行此操作。
所以你的代码应该是这样的:
var query = new azure.TableQuery()
.where('PartitionKey eq ?', 'MYKEY').and('RowKey ge ?', '<starts with substring>');