使用ExclusiveStartKey选项进行AWS Dynamodb扫描

Hyu*_*ang 6 node.js

对于我最近的项目,我试图从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);
    }
})
Run Code Online (Sandbox Code Playgroud)

}

这将继续"提供的起始键无效." 欢迎任何建议或帮助.

Hyu*_*ang 9

我发现了问题.我花了差不多一个星期.如果存在带分区键的排序键,则"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);
    }
})
Run Code Online (Sandbox Code Playgroud)

}

  • 谢谢,我也遇到了同样的问题,我添加了分区键和排序键,它起作用了。 (2认同)