2013-09-23 37 views
0

夥計們, 想獲得的代碼工作在一個表中返回的行數以下位:dynamodb行數

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. 

什麼是正確的合成文本得到行計數:)

謝謝!

回答

2

這個例外基本上告訴你,運算符'數'不被boto識別。

如果你在閱讀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'] 
1
from boto.dynamodb2.table import Table 
table = Table('current_fhv_drivers') 
print(table.query_count(number__eq = 'blah', expiration__eq = 'foo'))