0

伙计们,我试图让以下代码工作以返回表中的行数:

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.

获取行数的正确语法是什么:)

谢谢!

4

2 回答 2

2

该异常基本上是在告诉您 boto 无法识别运算符“count”。

如果您阅读http://boto.readthedocs.org/en/latest/dynamodb2_tut.html#querying上的第二段,您会看到:

过滤器参数作为 kwargs 传递并使用 __ 将字段名与用于过滤值的运算符分开。

所以我会将您的代码更改为:

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']
于 2013-10-20T14:47:14.977 回答
2
from boto.dynamodb2.table import Table
table = Table('current_fhv_drivers')
print(table.query_count(number__eq = 'blah', expiration__eq = 'foo'))
于 2015-08-18T22:08:04.537 回答