dynamodb行数通过python,boto查询

2024-07-08 11:33:02 发布

您现在位置:Python中文网/ 问答频道 /正文

各位, 我正在尝试使以下代码工作以返回表中的行计数:

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']

我看到的错误是:

^{pr2}$

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

谢谢!在


Tags: 代码fromimportfieldstablecurrentboto计数
2条回答
from boto.dynamodb2.table import Table
table = Table('current_fhv_drivers')
print(table.query_count(number__eq = 'blah', expiration__eq = 'foo'))

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

如果你读了关于http://boto.readthedocs.org/en/latest/dynamodb2_tut.html#querying的第二段,你会看到:

Filter parameters are passed as kwargs & use a __ to separate the fieldname from the operator being used to filter the value.

所以我把你的代码改成:

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']

相关问题 更多 >

    热门问题