使用查询从 DynamoDB 中检索所有项目? [英] Retrieve all items from DynamoDB using query?

查看:23
本文介绍了使用查询从 DynamoDB 中检索所有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用查询检索 dynamodb 表中的所有项目.以下是我的代码:

I am trying to retrieve all items in a dynamodb table using a query. Below is my code:

import boto.dynamodb2
from boto.dynamodb2.table import Table
from time import sleep

c    = boto.dynamodb2.connect_to_region(aws_access_key_id="XXX",aws_secret_access_key="XXX",region_name="us-west-2")

tab  = Table("rip.irc",connection=c)

x    = tab.query()

for i in x:
    print i
    sleep(1)

但是,我收到以下错误:

However, I recieve the following error:

ValidationException: ValidationException: 400 Bad Request
{'message': 'Conditions can be of length 1 or 2 only', '__type': 'com.amazon.coral.validate#ValidationException'}

我的代码非常简单,不属于 boto dynamodb2 文档,所以我不确定为什么会出现上述错误.任何见解都将不胜感激(对此是新的,有点迷失).谢谢

The code I have is pretty straightforward and out of the boto dynamodb2 docs, so I am not sure why I am getting the above error. Any insights would be appreciated (new to this and a bit lost). Thanks

我有一个哈希键和一个范围键.我可以通过特定的哈希键进行查询.例如,

I have both an hash key and a range key. I am able to query by specific hash keys. For example,

x = tab.query(hash__eq="2014-01-20 05:06:29")

我怎样才能检索所有项目?

How can I retrieve all items though?

推荐答案

啊,好吧,想通了.如果有人需要:

Ahh ok, figured it out. If anyone needs:

您不能在不指定特定哈希键的情况下对表使用查询方法.代替使用的方法是扫描.所以如果我替换:

You can't use the query method on a table without specifying a specific hash key. The method to use instead is scan. So if I replace:

x    = tab.query()

x    = tab.scan()

我得到了我桌子上的所有物品.

I get all the items in my table.

这篇关于使用查询从 DynamoDB 中检索所有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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