Javascript Dynamoose-无法使用2个键查询和查找位置
我已经在GitHub上打开了一个相关的问题,但也许这里的人能够更快地提供帮助 总结:Javascript Dynamoose-无法使用2个键查询和查找位置,javascript,nosql,amazon-dynamodb,dynamoose,Javascript,Nosql,Amazon Dynamodb,Dynamoose,我已经在GitHub上打开了一个相关的问题,但也许这里的人能够更快地提供帮助 总结: ValidationException:不支持查询键条件 我需要在给定位置的最后(数量)秒内查找记录。 非常简单,但已经与其他问题相关: 及 有效: Activity.query('locationId').eq(locationId).exec() 不起作用: Activity.query('locationId').eq(locationId).where('createdAt').ge(date.exec
ValidationException:不支持查询键条件
我需要在给定位置的最后(数量)秒内查找记录。
非常简单,但已经与其他问题相关:
及
有效:
Activity.query('locationId').eq(locationId).exec()代码>
不起作用:
Activity.query('locationId').eq(locationId).where('createdAt').ge(date.exec()代码>
代码示例:
模式
我怀疑createdAt
不是表/索引的范围键。您需要执行.filter('createdAt').ge(date)
或修改您的表/索引架构。我非常确定的问题是,当您在createdAt
属性上指定rangeKey:true
时,您正在告诉要在全局索引上使用它(我认为这不是正确的术语)。该范围键将链接到id
属性
我认为最简单的解决方案是将您的locationId
索引更改为以下内容:
index: {
global: true,
rangeKey: 'createdAt',
},
这样,您就非常明确地知道要将createdAt
设置为的rangeKey
进行更改后,请记住将更改与本地DynamoDB服务器或实际的DynamoDB服务同步,以便在代码和数据库系统中填充更改
希望这有帮助!如果它不能解决您的问题,请随时发表评论,我会进一步帮助您。请查看代码:createdAt:{type:Number,rangeKey:true,required:true,default:Date.now},
它是范围键。@gerrytan完全正确。我还提交了一个答案,其中给出了关于如何将索引设置为将createdAt
设置为范围键的更多细节。但是做过滤方法也应该可以。我不知道我可以为索引指定范围键。明天(今天是星期天:)我会检查一下,然后告诉你!你好它工作得很好,但只有一把钥匙。。。(但仍然非常感谢!)我正在努力进行查询:语言:{type:String,index:{global:true,rangeKey:'channel',},},channel:{type:String,rangeKey:true,index:{global:true,rangeKey:'messageCode',},},messageCode:{type:String,rangeKey:true,},
TranslationsModel.query('language').eq('EN').where('channel').eq(NotificationChannel.Email.)和().where('messageCode').eq('TEST_MSG').exec()代码>我可以在哪里做频道。。但是,当我添加和().where('messageCode')时,它会失败,因为
查询条件缺少键模式元素`像以前一样有什么好的建议吗?@MU仅用于范围键。试着改用。
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();
}
index: {
global: true,
rangeKey: 'createdAt',
},