Q: How do I create a global secondary index for a DynamoDB table?
All GSIs associated with a table must be specified at table creation
time. At this time, it is not possible to add a GSI after the table
has been created. For detailed steps on creating a Table and its
indexes, see here. You can create a maximum of 5 global secondary
indexes per table.
以下内容适用于AWS Lambda环境中的Node.js AWS SDK:
对我来说这是一个艰难的决定。我在尝试使用getItem方法时遇到了这个问题。不管我尝试了什么,我都会继续收到这个错误。我终于在AWS论坛上找到了一个解决方案:https://forums.aws.amazon.com/thread.jspa?threadID=208820
令人费解的是,这个明显的解决方案与我能找到的所有AWS文档都有冲突。
这是对我有用的代码:
要查询不是哈希键的字段,需要使用全局辅助索引(GSI)。查看this AWS Post了解有关GSI的更多详细信息
更新2015年2月:现在可以将GSI添加到现有表中。有关详细信息,请参见Amazon Docs。
很遗憾,you cannot add a GSI to an existing DynamoDB table因此,如果确实需要查询数据,则需要创建一个新表并导入数据。从DynamoDB FAQ:
如果不想移植数据,可以考虑创建第二个DynamoDB表,将电子邮件作为散列键,将父记录的散列用作对主数据表的查找,但正如您所想象的,这并不是一个最佳的解决方案,而且还带来了与主数据表保持同步的麻烦桌子。当我发送字符串而不是整数时,也出现了这个错误。
当然,这是我写数据库的时候,而不是读数据库的时候。
相关问题 更多 >
编程相关推荐