查询dynamoDB与非哈希键字段(博托/蟒蛇) [英] Query dynamoDB with non hash key field (with boto / python)

查看:682
本文介绍了查询dynamoDB与非哈希键字段(博托/蟒蛇)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用dynamoDB与博托,并有我的表的设计/查询有点问题的。

I'm using dynamoDB with boto, and having a bit of a problem in the design/query of my table.

我想我的数据看起来像

+---------------------------------------+
hash_key    account_id    mykey
-----------------------------------------
1           12345         myvalue1
2           12345         myvalue2
3           12345         myvalue3
4           123456        myvalue4
+---------------------------------------+

,然后检索所有数据的帐户12345综观博托文档,我总是需要有可用的hash_key。我知道我会质疑这个标准的SQL / MongoDB的,但我找不到博托一个解决方案。我想这是可能的吗?谢谢!

And then retrieve all data for account 12345. Looking at the boto docs, I always need to have the hash_key available. I know how I would query this standard SQL / MongoDB, but I can't find a solution for boto. I assume this is possible? Thanks!

编辑:这似乎工作

+---------------------------------------+
hash_key    range_key    mykey
-----------------------------------------
12345       12568        myvalue1
12345       53890        myvalue2
12345       12322        myvalue3
123456      23432        myvalue4
+---------------------------------------+

随后

> res = table.query(hash_key='12345')
> for item in res:
>    print i

因为我想抓住与账户#12345所有的条目,无论range_key的,我需要的查询而不是 get_item

推荐答案

我会用ACCOUNT_ID作为 hash_key 以及一些 range_key 来区分它们。

I would use the account_id as the hash_key along with some range_key to differentiate them.

在DynamoDB,主键组成的( hash_key range_key range_key 是可选的。这个元组必须是唯一的。请注意,您将需要整个元组访问给定元素 get_item

In DynamoDB, the primary key is composed of a (hash_key, range_key) range_key being optional. This tuple needs to be unique. Note that you will need the whole tuple to access a given element with get_item.

有一个AUTO_INCREMENT hash_key 是从SQL世界的一个坏习惯。

Having an 'auto_increment' hash_key is a bad habit from the SQL world.

如果您想了解更多关于这个问题,我写了一些背景做了dynamodb映射器文件中的建模数据:<一href="http://dynamodb-mapper.readthedocs.org/en/latest/api/model.html#auto-increment-when-to-use">http://dynamodb-mapper.readthedocs.org/en/latest/api/model.html#auto-increment-when-to-use

If you want to know more on this subject, I wrote some background do on modeling data in the dynamodb-mapper documentation: http://dynamodb-mapper.readthedocs.org/en/latest/api/model.html#auto-increment-when-to-use

这篇关于查询dynamoDB与非哈希键字段(博托/蟒蛇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆