【发布时间】:2017-12-21 20:01:52
【问题描述】:
我的 DynamoDB 表中的项目具有以下格式:
{
'id': 1,
'last_check': 1234556,
'check_interval': 100,
....
}
现在我想扫描表格并查找所有last_check + check_interval 小于某个给定值last_check_time 的项目。我没有找到创建组合两个属性的 FilterExpression 的方法,所以我目前正在按照以下方式进行操作:
last_check_time = time.time()
response = status_table.scan(
ProjectionExpression='id, last_check, check_interval',
FilterExpression = Attr('last_check').lt(last_check_time)
)
# manually filter the items and only preserve those with last_check + check_interval < last_check_time:
for item in response['Items']:
if item['last_check'] + item['check_interval'] < last_check_time:
# This is one of the items I'm interested in!
....
else:
# Not interested in this item. And I'd prefer to let DynamoDB filter this out.
continue
有没有办法让 DynamoDB 进行过滤,从而使上面示例中的 for 循环过时?
【问题讨论】:
标签: python-3.x amazon-web-services amazon-dynamodb boto3