【问题标题】:Global Secondary Index DynamoDB empty value error全局二级索引 DynamoDB 空值错误
【发布时间】:2022-11-21 19:03:36
【问题描述】:

我有一个可以为空值的字符串属性。我想将其设置为全球二级索引。但是当我尝试执行时它显示错误更新项目请求或者保存表语境:

Amazon.DynamoDBv2.AmazonDynamoDBException: One or more parameter values are not valid. A value specified for a secondary index key is not supported. The AttributeValue for a key attribute cannot contain an empty string value. IndexName: .... IndexKey: ...

我的心态或设置有什么问题?我是 DynamoDB 的新手并且有一个 MongoDB 基础。如果我不为此属性使用 GSI,如何对该属性执行查询?

我试过了

[DynamoDBIgnore] string property;
var operationConfig = new DynamoDBOperationConfig() { };
operationConfig.IsEmptyStringValueEnabled = true;
operationConfig.Conversion = DynamoDBEntryConversion.V2;

但它不起作用。

【问题讨论】:

  • 你能分享一下你是如何创建表格的吗?
  • 我创建了一个带有散列键的基表,并使用 .Net 中的对象持久性模型来保存/加载数据。
  • 您可以发布执行此操作的代码吗?

标签: amazon-dynamodb


【解决方案1】:

这表示您正在将 GSI PK 的值设置为空字符串 "",这是不受支持的。

为了克服这个问题,您只需从该属性中删除任何值,即根本不设置它。这使您的索引变得稀疏,因为它只会存储具有与之关联的键的数据。

【讨论】:

  • 您好,我使用的是.net DynamoDB SDK 的最新版本。我正在尝试通过 DynamoDBContext.SaveAsync() 保存文档。当我将其放入全局二级索引时,[DynamoDBIgnore] 属性似乎不起作用。
  • operationConfig.IsEmptyStringValueEnabled。可能是那行代码的结果?
  • 我试着评论这一行:operationConfig.IsEmptyStringValueEnabled 并继续使用 DynamoDBEntryConversion.V2,结果是一样的。
猜你喜欢
  • 1970-01-01
  • 2023-01-09
  • 1970-01-01
  • 1970-01-01
  • 2015-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-09
相关资源
最近更新 更多