dongmeiran609914 2016-08-10 10:21
浏览 111
已采纳

如何仅使用分区键从AWS Dynamodb获取数据?

I am using aws-sdk-go library for DynamoDb connectivity in Golang.

My DynamoDb table have a Partition key DeviceId (String) and a Sort Key Time (Number). How can I write GetItemInput to get all data with a specific DeviceId?

params := &dynamodb.GetItemInput{

    Key:    map[string]*dynamodb.AttributeValue {
        "DeviceId": {
            S: aws.String("item_1"),
        },
    },
    ExpressionAttributeNames: map[string]*string{
        "DeviceId": "DeviceId",
    },
    TableName:  aws.String("DbName"), 
}

list, err := svc.GetItem(params)
  • 写回答

1条回答 默认 最新

  • doupu3211 2016-08-10 15:12
    关注

    You have to use Query or Scan operation, this is a simple example but you can read more on Amazon documentation here

    In particular, Query operation

    A Query operation finds items in a table or a secondary index using only primary key attribute values

    var queryInput = &dynamodb.QueryInput{
        TableName: aws.String(dynamoRestDataTableName),
        KeyConditions: map[string]*dynamodb.Condition{
            "DeviceId": {
                ComparisonOperator: aws.String("EQ"),
                AttributeValueList: []*dynamodb.AttributeValue{
                    {
                        S: aws.String("aDeviceId"),
                    },
                },
            },
        },
    }
    
    var resp, err = dynamoSvc.Query(queryInput)
    if err != nil {
        return nil, err
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?