2017-09-30 4 views
0

pynamodb을 사용하여 테이블의 특정 해시 키와 일치하는 모든 범위 키를 가져 오려고합니다. 내가하지 않아도 쿼리 수준으로 필터링 논리를 이동하려는pynamodb - 해시 키만 사용하여 DB 항목 가져 오기

from pynamodb.models import Model 
from pynamodb.attributes import UnicodeAttribute 

class Users(Model): 
    class Meta: 
     table_name = 'user_posts' 
    username = UnicodeAttribute(hash_key=True) 
    post_id = UnicodeAttribute(range_key=True) 

# Get all post_id's for a username 
user = 'johndoe22' 
posts = [] 

for entry in Users.scan(): 
    if entry.username == user: 
     posts.append(entry.post_id) 

:

는 내가 검사를 수행 한 후 해시 키과 같이 일치 항목을 필터링 할 수 있습니다 알고 db의 전체 내용을 끌어 내려고 이것을 어떻게 할 수 있습니까?

답변