node.js - 如何根据时间戳和此时间戳值的偏移量获取 DynamoDB 表过滤器中的项目?
问题描述
我有具有以下架构的 DynamoDB 表:
var params = {
TableName : "SomeTable",
KeySchema: [
{ AttributeName: "userid", KeyType: "HASH"}, //Partition key
{ AttributeName: "transactionId", KeyType: "RANGE" } //Sort key
],
AttributeDefinitions: [
{ AttributeName: "userid", AttributeType: "S" },
{ AttributeName: "transactionId", AttributeType: "S" },
],
GlobalSecondaryIndexes: [
{
IndexName: "TransactionIndex",
KeySchema: [
{
AttributeName: "transactionId",
KeyType: "HASH"
},
{
AttributeName: "productId",
KeyType: "RANGE"
}
],
Projection: {
ProjectionType: "ALL"
},
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
};
我正在查询这个表,根据时间值进行过滤,但是我找不到任何关于如何在 FilterExpression 中修改这个值的文档。这个想法是找到所有 expiry_date_ms 值即将到期或刚刚到期(即前 1 天或后 1 天)的行,如下所示:
var startoffset = 86400000; // one day before
var endoffset = 86400000; // one day after
var params = {
TableName: "SomeTable",
FilterExpression: "#tm between :start and :end'",
ExpressionAttributeNames: { "#tm": "expiry_date_ms" },
ExpressionAttributeValues:{ ":start": "expiry_date_ms" - startoffset, ":end": "expiry_date_ms" + endoffset }
};
docClient.scan(params, function(err, data) {
if (err) {
console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
} else {
console.log(params);
console.log("Scan succeeded.");
data.Items.forEach(function(item) {
console.log("Item :" + JSON.stringify(item));
});
}
});
也许我的逻辑完全错误,并且有更好/更聪明的方法来运行此类查询,或者在我的情况下,最好的方法是扫描或查询。任何有关该问题的信息将不胜感激。
解决方案
推荐阅读
- .net - 如何创建 dotNet 6 自安装服务?
- python - pingouin.rm_anova,重复测量方差分析错误。蟒蛇,熊猫
- python - 如何使用 AWS Glue 和其他 AWS 服务从 Oracle 数据库中提取数据
- visual-studio-code - 自动完成在 VSCode GraphQL 扩展中不起作用
- python - pandas 按列值分组并提取一列文本
- python - 当有相似的值时,如何在熊猫数据框中删除行?
- python - 星期字段中的气流哈希“#”运行不正常
- google-cloud-platform - Google AI Platform:错误代码 400:响应大小太大
- pandas - 如何从 DataFrame 中提取一行作为 Series,并将 DataFrame 中的列名作为 Series 中的行索引?
- java - 将数据库连接到 TableView 时出现“java.lang.reflect.InvocationTargetException”