boto dynamodb2: Can I query a table using range key only?

后端 未结 3 858
暖寄归人
暖寄归人 2021-01-02 06:01

In one of my python application, I am using boto and I want to query a dynamodb table using range key only. I don\'t want to use scan.

Schema for ratings tab

相关标签:
3条回答
  • 2021-01-02 06:14

    The behavior you want can be achieved using a global secondary index that uses photo_id as a hash key.

    0 讨论(0)
  • 2021-01-02 06:14

    In AWS SDKv2 you can scan table using AWSDynamoDBScanExpression, eg. iOS:

     AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
     AWSDynamoDBScanExpression *scanExpression = [AWSDynamoDBScanExpression new];
     scanExpression.exclusiveStartKey = nil;
     scanExpression.limit = @20;
     [[[dynamoDBObjectMapper scan:[DDBTableRow class]
                       expression:scanExpression]
       continueWithExecutor:[BFExecutor mainThreadExecutor] withSuccessBlock:^id(BFTask *task) {...}
    

    If you need a condition can use AWSDynamoDBCondition:

     AWSDynamoDBCondition *condition = [AWSDynamoDBCondition new];
     AWSDynamoDBAttributeValue *attribute = [AWSDynamoDBAttributeValue new];
     attribute.N = @"400";
     condition.attributeValueList = @[attribute];
     condition.comparisonOperator = AWSDynamoDBComparisonOperatorEQ;
     scanExpression.scanFilter = @{@"latitude": condition};
    
    0 讨论(0)
  • 2021-01-02 06:26

    When using a Query operation on DynamoDB you must supply one hash key, it is not defined as part of the range_key_conditions as you can see in the documentation - so you will have to use user_id_eq as you already figured out.

    If you need to get rows from more than one hash key in one API call, you must use Scan (you can fetch multiple rows using batchGet but this is irrelevant to your scenario)

    P.s, it appears your secondary index is the same as the Range key, is that a mistake?

    0 讨论(0)
提交回复
热议问题