This is a continuation** of my quest to switch from regular DynamoDB tables to DynamoDB2 ones with Global Secondary Indices.
So I created my table as shown here and then added the following two elements:
table.put_item(data={'firstKey': 'key01', 'message': '{"firstKey":"key01", "comments": "mess 1 w/o secondKey"}'})
table.put_item(data={'firstKey': 'key02', 'secondKey':'skey01', 'message': '{"firstKey":"key02", "parentId":"skey01", "comments": "mess 2 w/ secondKey"}'})
What I want to do now is retrieve items by either their (i) unique firstKey
values or (ii) unique secondKey
values. The 1st one is easy:
res1 = table.get_item(firstKey='key01')
res1['message']
I can't figure out how to do the 2nd one. This does not work:
res2 = table.get_item(secondKey='skey01')
producing The provided key element does not match the schema
. OK that's expected. When I do this:
res2 = table.query(secondKey='skey01',index='secondKeyIndex')
I get You must specify more than one key to filter on
.
So how do I get it to work? Note that when I have the value of secondKey
of an item, I do NOT know its corresponding firstKey
.
===== UPDATE: Here are a couple of other things that I've tried:
This
res2 = table.query(secondKey__eq='skey01',index='secondKeyIndex')
produced
boto.dynamodb2.exceptions.QueryError: You must specify more than one key to filter on.
In the block below, the query
statement did not produce any errors
res2 = table.query(secondKey='skey01',secondKey__eq='skey01',index='secondKeyIndex')
for r in res2:
print res2['secondKey']
but the print
gave me
boto.dynamodb2.exceptions.UnknownFilterTypeError: Operator 'secondKey' from 'secondKey' is not recognized.