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