Querying DynamoDB by date

前端 未结 7 1359
予麋鹿
予麋鹿 2020-11-28 03:07

I\'m coming from a relational database background and trying to work with amazon\'s DynamoDB

I have a table with a hash key \"DataID\" and a range \"CreatedAt\" and

7条回答
  •  不知归路
    2020-11-28 03:12

    You can have multiple identical hash keys; but only if you have a range key that varies. Think of it like file formats; you can have 2 files with the same name in the same folder as long as their format is different. If their format is the same, their name must be different. The same concept applies to DynamoDB's hash/range keys; just think of the hash as the name and the range as the format.

    Also, I don't recall if they had these at the time of the OP (I don't believe they did), but they now offer Local Secondary Indexes.

    My understanding of these is that it should now allow you to perform the desired queries without having to do a full scan. The downside is that these indexes have to be specified at table creation, and also (I believe) cannot be blank when creating an item. In addition, they require additional throughput (though typically not as much as a scan) and storage, so it's not a perfect solution, but a viable alternative, for some.

    I do still recommend Mike Brant's answer as the preferred method of using DynamoDB, though; and use that method myself. In my case, I just have a central table with only a hash key as my ID, then secondary tables that have a hash and range that can be queried, then the item points the code to the central table's "item of interest", directly.

    Additional data regarding the secondary indexes can be found in Amazon's DynamoDB documentation here for those interested.

    Anyway, hopefully this will help anyone else that happens upon this thread.

提交回复
热议问题