2016-10-12 6 views
1

최근 프로젝트에서 dynamodb에서 데이터를 가져 오려고합니다. 그리고 내 모든 매개 변수에 "exclusiveStartKey"옵션을 추가하는 것 외에는 아무 문제가없는 것 같습니다.ExclusiveStartKey 옵션을 사용하는 AWS Dynamodb 스캔

아래 코드는 제 코드입니다.

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); 
    } 
}) 

}

반환이 유지 "제공된 시작 키가 유효하지 않습니다." 조언이나 도움을 환영합니다.

답변

1

나는이 문제를 발견했다. 거의 일주일이 걸렸습니다. 파티션 키가있는 정렬 키가 있으면 "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); 
    } 
}) 

}

관련 문제