我已经在 GitHub 上打开了一个相关问题,但也许这里有人可以更快地提供帮助。
概括:
ValidationException: Query key condition not supported
我需要在给定位置的最后(数量)秒内查找记录。很简单,但已经与其他问题相关:
一个和另一个
作品:
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();
}