我正在尝试扫描和过滤来自dynamodb的集合,如下所示:
{
"id": 4,
"car_type_id": 1,
"car_performance": {
"question": [
{
"answer": false,
"answer_type": "BO",
"question_id": 1
},
{
"answer": 402.3,
"answer_type": "FL",
"question_id": 2
},
{
"answer": "2019-07-17 10:44:04",
"answer_type": "DT",
"question_id": 3
}
],
"engine": {
"is_active": true,
"total_score": 65.4
},
"acceleration": {
"is_active": true,
"total_score": 77
},
"hydraulics": {
"is_active": true,
"total_score": 45
}
}
}
我正在尝试获取所有具有car_type_id == 1
和engine.total_score between 50 to 80
的列表,并且包含ID 2和3
我有这样的查询,
engine = {
"is_active": true,
"total_score": 65.4
}
table = dynamodb.Table('CarDetails')
response = table.scan(
FilterExpression=Attr('job_stage_id').eq(1) & (Attr('engine').conatins(engine))
)
我不明白如何与其他人一起应用范围。id 可以应用类似 、
select * from CarDetails where car_performance.engine.total_score between 50 and 80 and car_type_id = 1 car_performance.questions.question_id contains [2,3]
您可以使用
between()
方法来执行此操作:
FilterExpression=Attr('job_stage_id').eq(1) &
(Attr('engine').contains(engine)) & (Attr('total_score').between(50, 80))
有关可能条件的文档,请点击此处:https://boto3.amazonaws.com/v1/documentation/api/latest/_modules/boto3/dynamodb/conditions.html