Dynamodb查询具有多个属性值

时间:2015-03-23 19:45:06

标签: python amazon-web-services amazon-dynamodb boto

如何使用多个值进行查询? 例如,所有使用last_name [[Doggett“,”Scully“,”Mulder“]的用户

使用boto的例子。

    Table.create('users', 
        schema=[
            HashKey('id') # defaults to STRING data_type
        ], throughput={
            'read': 5,
            'write': 15,
        }, global_indexes=[
            GlobalAllIndex('LastnameTimeIndex', parts=[
                HashKey('last_name'),
                RangeKey('creation_date', data_type=NUMBER),
            ],
            throughput={
                'read': 1,
                'write': 1,
            }),
        ],
        connection=conn
   )

类似的东西:

table = Table("users", connections=conn)
table.query_2(last_name__in=["Doggett","Scully","Mulder"], connection=conn)

2 个答案:

答案 0 :(得分:2)

目前,查询API不支持IN条件为KeyCondition。正如Max所建议的那样,您需要进行单独的查询。您还可以并行进行查询以提高性能。

如果您想使用IN,则需要进行扫描(或在您的示例中进行索引扫描)。

答案 1 :(得分:1)

您必须执行三个单独的查询。每个姓氏一个。