我是aws dynamodb的新手,并按如下所示命中了查询
let params = {
TableName: tableName
};
if (from && to) {
params.FilterExpression = 'createdOn >= :from and createdOn <= :to';
params.ExpressionAttributeValues = { ":from": from, ":to": to }
}
return new Promise((resolve, reject) => {
docClient.scan(params, (err, data) => {
if (err) {
//do stuff
}else{//do stuff}
});
});
这是我的数据库模式
const ApplicationDataSchema = {
TableName: "data1", //config.get('aws_tables.APPLICATIONS_DATA'),
KeySchema: [
{ AttributeName: "id", KeyType: "HASH" },
{ AttributeName: 'createdOn', KeyType: 'RANGE' }
],
AttributeDefinitions: [
{ AttributeName: "id", AttributeType: "S" },
{ AttributeName: 'createdOn', AttributeType: 'N' }
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}
是否需要更改模式,我没有得到正确的结果。 createdOn字段包含epoc时间,例如:“ 1548659664131”
答案 0 :(得分:0)
如果要使用带有2个日期的过滤器表达式,则可能正在寻找BETWEEN语句。
'#createdOn在:from和:to之间
我建议您看看this guide on AWS,将dynamodb与javascript一起使用。