我已经在GitHub上打开了一个相关的问题,但也许这里的人可以帮助更快。
摘要:
ValidationException: Query key condition not supported我需要在给定的位置上找到最后(数量)秒的记录。相当简单,但已经与其他问题相关:一和另一个
WORKS:
Activity.query('locationId').eq(locationId).exec();
不工作:
Activity.query('locationId').eq(locationId).where('createdAt').ge(date).exec();
代码示例:
模式
const Activity = (dynamoose: typeof dynamooseType) => dynamoose.model<ActivityType, {}>('Activity',
new Schema({
id: {
type: String,
default: () => {
return uuid();
},
hashKey: true,
},
userId: {
type: String,
},
locationId: {
type: String,
rangeKey: true,
index: {
global: true,
},
},
createdAt: { type: Number, rangeKey: true, required: true, default: Date.now },
action: {
type: Number,
},
}, {
expires: 60 * 60 * 24 * 30 * 3, // activity logs to expire after 3 months
}));执行函数的代码
有趣的是,我发现这是我建议的解决办法,直到他们合并PR,赋予指定时间戳作为键的能力,但不幸的是,它不起作用。
async getActivitiesInLastSeconds(locationId: string, timeoutInSeconds: number) {
const Activity = schema.Activity(this.dynamoose);
const date = moment().subtract(timeoutInSeconds, 'seconds').valueOf();
return await Activity.query('locationId').eq(locationId)
.where('createdAt').ge(date).exec();
}发布于 2018-09-22 11:01:36
我怀疑createdAt不是表/索引的范围键。您需要执行.filter('createdAt').ge(date)或修改表/索引架构。
发布于 2018-09-22 23:08:00
我很确定问题是,当您在rangeKey: true属性上指定createdAt时,您告诉我们要在全局索引上使用它(我不认为这是正确的术语)。该范围键将链接到id属性。
我认为最简单的解决方案是将locationId索引更改为如下所示:
index: {
global: true,
rangeKey: 'createdAt',
},这样,您将非常明确地说明要将createdAt设置为rangeKey的索引。
进行更改后,请记住将更改与本地DynamoDB服务器或实际的DynamoDB服务同步,以便在代码和数据库系统中填充更改。
希望这能帮上忙!如果它不能解决你的问题,请随时评论,我会进一步帮助你。
https://stackoverflow.com/questions/52455680
复制相似问题