英文:
How to use "BETWEEN" in aws-sdk-go Dynamodb QueryInput?
问题
我正在使用aws-sdk-go来操作DynamoDB。我需要从我的数据库中收集一些项目。过滤条件是deviceid: xyz,time >= 10和time <= 20。
time是我的数据库的排序键,deviceid是主键。我理解我需要使用BETWEEN来实现我的目标。我的实现不成功,如下所示:
var queryInput = &dynamodb.QueryInput{
TableName: aws.String(dbName),
KeyConditions: map[string]*dynamodb.Condition{
"deviceid": {
ComparisonOperator: aws.String("EQ"),
AttributeValueList: []*dynamodb.AttributeValue{
{
S: aws.String("xyz"),
},
},
},
"time": {
ComparisonOperator: aws.String("BETWEEN"),
AttributeValueList: []*dynamodb.AttributeValue{
{
N: aws.String("10"),
},
{
N: aws.String("20"),
},
},
},
},
}
这里有哪些错误?
英文:
I am using aws-sdk-go for dynamodb. I need to collect some items from my DB. The filtering conditions are deviceid: xyz, time >= 10 and time <= 20.
time is the sort key for my db and deviceid is the primary key. I understand I have to use BETWEEN for achieving my goal. My Implementations are not successful and as follows:
var queryInput = &dynamodb.QueryInput{
TableName: aws.String(dbName),
KeyConditions: map[string]*dynamodb.Condition{
"deviceid": {
ComparisonOperator: aws.String("EQ"),
AttributeValueList: []*dynamodb.AttributeValue{
{
S: aws.String("xyz"),
},
},
},
"time": {
ComparisonOperator: aws.String("BETWEEN"),
AttributeValueList: []*dynamodb.AttributeValue{
{
N: aws.String("10"),
N: aws.String("20"),
},
},
},
},
}
What are the mistakes I made here?
答案1
得分: 5
"time"的值应按照以下方式给出:
"time": {
ComparisonOperator: aws.String("BETWEEN"),
AttributeValueList: []*dynamodb.AttributeValue{
{
N: aws.String("10"),
},
{
N: aws.String("20"),
},
},
},
英文:
The time
value should be given as mentioned below:-
"time": {
ComparisonOperator: aws.String("BETWEEN"),
AttributeValueList: []*dynamodb.AttributeValue{
{
N: aws.String("10"),
},
{
N: aws.String("20"),
},
},
},
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论