user2121530
user2121530

Reputation: 107

Dynamodb queries with more than one value for atribute

How can I make a query using more than one value? For example, all users with last_name ["Doggett","Scully","Mulder"]

Example using 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
   )

something like:

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

Upvotes: 2

Views: 815

Answers (2)

Johnny Wu
Johnny Wu

Reputation: 862

Currently, the Query API doesn't support the IN condition as a KeyCondition. As suggested by Max, you'll need to make separate queries. You can also make the queries in parallel to improve performance.

If you want to use IN, you'll need to do a scan (or index scan in your example) instead.

Upvotes: 3

Max
Max

Reputation: 8836

You have to do three separate Queries. One for each last name.

Upvotes: 1

Related Questions