作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我在 Golang 中使用 aws-sdk-go 库进行 DynamoDb 连接。
我的 DynamoDb 表有一个分区键 DeviceId(字符串)和一个排序键时间(数字)。如何编写 GetItemInput 以获取具有特定 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)
最佳答案
您必须使用查询或扫描操作,这是一个简单的示例,但您可以在亚马逊文档上阅读更多信息 here
特别是查询操作
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
}
关于amazon-web-services - 如何仅使用分区键从 aws Dynamodb 获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38870638/
我是一名优秀的程序员,十分优秀!