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查询


- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01