dynamodb row count via python, boto query(通过python的dynamodb行数,boto查询)
问题描述
各位,我正在尝试让以下代码工作以返回表中的行数:
Folks, Am trying to get the following bit of code working to return the row count in a table:
import boto
import boto.dynamodb2
from boto.dynamodb2.table import Table
from boto.dynamodb2.fields import HashKey, RangeKey
drivers = Table('current_fhv_drivers')
rowcountquery = drivers.query(
number = 'blah',
expiration = 'foo',
count=True,
)
for x in rowcountquery:
print x['Count']
我看到的错误是:
boto.dynamodb2.exceptions.UnknownFilterTypeError: Operator 'count' from 'count' is not recognized.
获取行数的正确语法是什么:)
Whats the correct syntaxt to get row count :)
谢谢!
推荐答案
那个异常基本上是在告诉你操作符'count'不被boto识别.
That exception is basically telling you that the operator 'count' is not recognized by boto.
如果您阅读 http://boto.readthedocs.org 上的第二段/en/latest/dynamodb2_tut.html#querying 你会看到:
If you read the second paragraph on http://boto.readthedocs.org/en/latest/dynamodb2_tut.html#querying you'll see that:
过滤器参数作为 kwargs &使用 __ 将字段名与用于过滤值的运算符分开.
Filter parameters are passed as kwargs & use a __ to separate the fieldname from the operator being used to filter the value.
所以我会将您的代码更改为:
So I would change your code to:
import boto
import boto.dynamodb2
from boto.dynamodb2.table import Table
from boto.dynamodb2.fields import HashKey, RangeKey
drivers = Table('current_fhv_drivers')
rowcountquery = drivers.query(
number__eq = 'blah',
expiration__eq = 'foo',
count__eq = True,
)
for x in rowcountquery:
print x['Count']
这篇关于通过python的dynamodb行数,boto查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过python的dynamodb行数,boto查询
基础教程推荐
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
