【问题标题】:Checking if an entity exists in Azure Table Storage检查 Azure 表存储中是否存在实体
【发布时间】:2017-01-04 12:32:56
【问题描述】:

我正在尝试通过 PartitionKey 和 RowKey 从 Azure 表存储中检索实体。当我的表中实际上存在具有这些键的实体时,这非常有用。

tableService.retrieveEntity(tableName, partition, row, (err, res, resp) => {
    ...    
}

但是,当没有找到带有 for 键的实体时,我只会收到一个相当不清楚的错误,说“其中一个请求输入无效”...

未处理的拒绝 StorageError:请求输入之一无效。

有什么方法可以检查特定 Partition- 和 RowKey 的实体是否存在?

【问题讨论】:

  • 如果实体不存在,那么您应该得到 404(未找到)错误,而不是您得到的错误。您收到的错误表明您提供的值有问题。你能分享一个PartitionKeyRowKey 的例子吗?
  • 我实际上在我的 RowKey 参数中使用了不允许的字符。感谢您的提醒。

标签: node.js azure azure-table-storage azure-functions


【解决方案1】:

我尝试了您的代码来检索不存在的实体,然后我收到以下错误:

{ ...
  name: 'StorageError',
  message: 'The specified resource does not exist.\nRequestId:c9f87517-0002-0028-5e32-660f88000000\nTime:2017-01-04T02:30:10.0502844Z',
  code: 'ResourceNotFound',
  statusCode: 404,
  requestId: 'c9f87517-0002-0028-5e32-660f88000000' }

当我插入一个日期错误的实体时,代码如下所示:

var task = {
  PartitionKey: {'_': 'hometasks'},
  RowKey: {'_': '1'},
  description: {'_': 'take out the trash'},
  dueDate: {'_': 'somethingwronghere', '$': 'Edm.DateTime'}
};

tableSvc.insertEntity('mytable',task, function (error, result, response) {
  console.log(error);
});

然后我得到与你相同的错误:

 { ...
  message: 'One of the request inputs is not valid.\nRequestId:2e8e6c07-0002-003a-7135-663b94000000\nTime:2017-01-04T02:49:02.8761981Z',
  code: 'InvalidInput',
  statusCode: 400,
  requestId: '2e8e6c07-0002-003a-7135-663b94000000' }

所以请仔细检查您是否收到了相应的错误信息。

【讨论】:

猜你喜欢
  • 2011-02-08
  • 1970-01-01
  • 2013-07-05
  • 2014-06-06
  • 1970-01-01
  • 1970-01-01
  • 2012-12-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多