简体   繁体   English

包含时间戳的 DynamoDb 级联密钥

[英]DynamoDb concatenated Key that includes a timestamp

I have a DynamoDb table with the following key structure,我有一个具有以下关键结构的 DynamoDb 表,

Hash     Range
string   string|string|timestamp(string)
12345    ABC|DEF|123456789

I want to be able to get items that have a timestamp which is equal or less than the time stamp part in the range key, but I am not sure whether my implementation is correct or not or if there are edge cases that this doesn't work so I want to get a second opinion.我希望能够获得时间戳等于或小于范围键中的时间戳部分的项目,但我不确定我的实现是否正确,或者是否存在不正确的边缘情况工作,所以我想获得第二意见。

here is my implementation:这是我的实现:

var asyncSearch = _dynamoDbContext.QueryAsync<PricingModel>(entityKeyId,
                    new DynamoDBOperationConfig
                    {
                        OverrideTableName = _config.Value.PricingModelTableNameOverride,
                        QueryFilter = new List<ScanCondition>
                        {
                            new ScanCondition(nameof(PricingModel.EntityKeyId),
                                ScanOperator.Equal,
                                entityKeyId),
                            new ScanCondition(nameof(PricingModel.SortKeyId),
                                ScanOperator.LessThanOrEqual,
                                sortKeyId)
                        }
                    });

There is very little information to go on here (for example what are the other components of the range key, and what will you use them for).这里没有什么信息要讲(例如,范围键的其他组件是什么,您将使用它们做什么)。 However, it looks like you need to move the position of the timestamp to the start of the range key.但是,看起来您需要将时间戳的位置移动到范围键的开头。

DynamoDB will order the items within the partition key by the range key. DynamoDB 将按范围键对分区键内的项目进行排序。 If you want them date ordered, you will need the timestamp as the first part of the range key.如果您希望它们按日期排序,您将需要时间戳作为范围键的第一部分。

As your range key is a string, make sure you choose a date format that sorts naturally as a string.由于您的范围键是一个字符串,因此请确保您选择的日期格式可以自然地作为字符串进行排序。

EDIT: ISO 8601 strings (eg 2019-04-11T11:37:00Z) are naturally sortable as a string, and also human readable.编辑:ISO 8601 字符串(例如 2019-04-11T11:37:00Z)自然可以作为字符串进行排序,并且也是人类可读的。

EDIT: You can then use the LT key condition operator for less than, and BEGINS_WITH for an exact timestamp编辑:然后您可以使用LT键条件运算符小于和BEGINS_WITH为确切的时间戳

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM