0

下面的函数应该很简单吧?这也是我的想法。尽管如此,对于我的生活,我无法弄清楚为什么我总是收到一条错误消息,告诉我一个“ValidationException”,出现错误通知我“Query key condition not supported”。用AWS DocumentClient小于二级索引查询 - “查询键条件不支持”

const getUpdated = (refreshDatetime, callback) => { 

    refreshDatetime = parseInt(refreshDatetime); 

    docClient.query({ 
    TableName: 'aw-reach', 
    IndexName: 'updateDatetime-index', 
    KeyConditionExpression: ':refreshDatetime < updateDatetime', 
    ExpressionAttributeValues: { 
     ':refreshDatetime': refreshDatetime, 
    } 
    }, (error, data) => { 
    if (error) callback(error, null); 
    callback(null, data.Items); 
    }); 
}; 

只是为了确保我没有做其他任何事情令人难以置信的愚蠢的(一个明显的可能性也一样),这里是我使用的测试片段。

const refreshDatetime = Date.parse('01 Jan 2015'); 
getUpdated(refreshDatetime, (error, response) => { 
    console.log(JSON.stringify(response)); 
}); 

洞察和想法的欢迎和高度赞赏为编写代码,甚至这小小的代码,绝对不是我的最强的天赋!

更新:要添加更多详细信息,我的散列键是reachId,与我的二级索引关联的分区键是updateDatetime

enter image description here

+0

是refreshDatetime你的散列键? –

+0

它是与索引关联的分区键。 – knu2xs

回答

2

Dynamodb不允许使用任何其他条件,除非“=”上散列/分区键。

您可以选择使用范围/排序键的其他表达式,但不能用于散列键。

参考:Documentation link

Another post with similar problem

希望有所帮助。

+0

非常感谢您对文档的解释和链接。尽管我一直试图通过文档来阅读,但我倾向于在可以找到关于同一主题的文档的所有不同地方之间迷失方向。感谢您帮助我找到干草堆里的针! – knu2xs