对于我最近的项目,我试图从 dynamodb 获取数据。除了我在参数中添加“exclusiveStartKey”选项之外,似乎一切正常。
下面是我的代码。
function scanDataFromDB(datetime) {
let params = {
TableName: TABLE_NAME,
IndexName: "main-index",
Select: "ALL_ATTRIBUTES",
ExclusiveStartKey: {
"message_id": { "S": "20161011175258875925351560"}
},
ExpressionAttributeNames: {
"#f_up": "date_updated"
},
ExpressionAttributeValues: {
":s_time": "2016-10-11 00:00:00",
":e_time": "2016-10-11 23:59:59"
},
FilterExpression: "#f_up between :s_time and :e_time",
ScanIndexForward: "true"
};
console.log(params);
docClient.scan(params, function(err, data) {
if(err) {
console.log(JSON.stringify(err, null, 2));
//callback(err, null);
} else {
console.log(JSON.stringify(data, null, 2));
//callback(null, err);
}
})
}
这会不断返回“提供的启动密钥无效。”
我发现了问题所在。我花了将近一周的时间。如果存在带有分区键的排序键,“ExclusiveStartKey”选项必须同时指示分区键和排序键。
function scanDataFromDB(datetime) {
let params = {
TableName: TABLE_NAME,
IndexName: "main-index",
Select: "ALL_ATTRIBUTES",
ExclusiveStartKey: {
"message_id": "20161012114321726034249204",
"date_updated": "2016-10-12 11:44:09"
},
ExpressionAttributeNames: {
"#f_up": "date_updated"
},
ExpressionAttributeValues: {
":s_time": "2016-10-11 00:00:00",
":e_time": "2016-10-11 23:59:59"
},
FilterExpression: "#f_up between :s_time and :e_time",
ScanIndexForward: "true"
};
console.log(params);
docClient.scan(params, function(err, data) {
if(err) {
console.log(JSON.stringify(err, null, 2));
//callback(err, null);
} else {
console.log(JSON.stringify(data, null, 2));
//callback(null, err);
}
})
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)