python C boto dynamodb2:我可以只使用范围键查询表吗?
发布时间:2023-12-17 00:15:50 所属栏目:Python 来源:DaWei
导读: 在我的一个
python应用程序中,我正在使用boto,我想只使用范围键查询dynamodb表.我不想使用扫描.
评级表的模式
ratings = Table.create('ratings',schema=[
HashKey('user_i
python应用程序中,我正在使用boto,我想只使用范围键查询dynamodb表.我不想使用扫描.
评级表的模式
ratings = Table.create('ratings',schema=[
HashKey('user_i
在我的一个 python应用程序中,我正在使用boto,我想只使用范围键查询dynamodb表.我不想使用扫描. 评级表的模式 ratings = Table.create('ratings',schema=[ HashKey('user_id',data_type=NUMBER),RangeKey('photo_id',data_type=NUMBER) ],throughput={ 'read': 5,'write': 15,},indexes = [ AllIndex('rating_allindex',parts=[ HashKey('user_id',data_type=NUMBER) ]) ]) from boto.dynamodb2.table import Table ratings = Table('ratings') # photo_id is range_key and user_id is hash_key ratings_list = ratings.query(photo_id__eq=1)这样做,我得到此错误查询条件错过了关键架构元素user_id. 但它显示错误,不支持查询键条件.我想只有hash_key允许使用过滤器__eq.我如何实现我想要的目标? 解决方法 在DynamoDB上使用 Query操作时,必须提供一个哈希键,它没有被定义为range_key_conditions的一部分,正如您在文档中看到的那样 C 因此您必须使用已经找到的user_id_eq.如果需要在一次API调用中从多个哈希键中获取行,则必须使用“扫描”(可以使用batchGet获取多行,但这与您的方案无关) P.s,看来你的二级索引与Range键相同,那是一个错误吗? (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐