问题描述
各位,我正在尝试让以下代码工作以返回表中的行数:
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查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)