我已经在GitHub上打开了一个相关问题,但也许有人可以更快地提供帮助。

概要:
ValidationException: Query key condition not supported我需要在给定位置的最后(数量)秒内找到记录。
非常简单,但是已经与其他问题相关:
Oneanother one

作品:
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();
  }

最佳答案

我怀疑createdAt不是您的表/索引的范围键。您需要执行.filter('createdAt').ge(date)或修改表/索引架构。

关于javascript - Dynamoose-无法通过2键查询以及在哪里,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52455680/

10-12 13:02