这是我从常规 DynamoDB 表切换到具有全局二级索引的 DynamoDB2 表的延续**。
所以我创建了如图所示的表格here https://stackoverflow.com/questions/21736813/getting-attributeerror-when-trying-to-create-dynamodb-table-with-global-index-us然后添加以下两个元素:
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"}'})
我现在想做的是通过(i)唯一的来检索项目firstKey
价值观或 (ii) 独特secondKey
价值观。第一个很简单:
res1 = table.get_item(firstKey='key01')
res1['message']
我不知道如何做第二个。这不起作用:
res2 = table.get_item(secondKey='skey01')
生产The provided key element does not match the schema
。好的,这是预期的。当我这样做时:
res2 = table.query(secondKey='skey01',index='secondKeyIndex')
I get You must specify more than one key to filter on
.
那么我该如何让它发挥作用呢?请注意,当我的值为secondKey
一个项目,我不知道它对应的firstKey
.
=====
更新:这是我尝试过的其他一些事情:
This
res2 = table.query(secondKey__eq='skey01',index='secondKeyIndex')
produced
boto.dynamodb2.exceptions.QueryError: You must specify more than one key to filter on.
在下面的块中,query
语句没有产生任何错误
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.