具有多个属性值的 Dynamodb 查询

Dynamodb queries with more than one value for atribute

如何使用多个值进行查询? 例如,所有 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)

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

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

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