我是 Dynamo 的新手,一直在尝试查询数据库的范围。
我在我的 Lambda 中查询 ISO 日期字符串,如下所示:
const start = event['queryStringParameters']['startDate'];
const end = event['queryStringParameters']['endDate'];
let params = {
TableName: "Parcel",
KeyConditionExpression: "#trackNo = :trackNo AND #ShipmentDate BETWEEN :start AND :end",
ExpressionAttributeNames: {
"#trackNo": "TrackingNumber",
"#ShipmentDate": "ShipmentDate"
},
ExpressionAttributeValues: {
":trackNo": "TrackingNumber",
":start": start,
":end": end
}
但我没有得到该范围内的任何记录...
我已经搜索了几个小时......我无法弄清楚如何执行这个查询。
示例数据:
{
"Carrier": "FedEx",
"ShipmentDate": "2019-09-02",
"TrackingNumber": "TN_2019-09-02"
}
功能扫描范例:
let params = {
TableName: "Parcel",
FilterExpression: "#ShipmentDate BETWEEN :start AND :end",
ExpressionAttributeNames: {
"#ShipmentDate": "ShipmentDate"
},
ExpressionAttributeValues: {
":start": start,
":end": end
}
};
try {
const data = await documentClient.scan(params).promise();
responseBody = JSON.stringify(data);
statusCode = 200;
} catch (err) {
responseBody = `Unable to get shipments: ${err}`
statusCode = 403;
}