如何在aws-sdk-go Dynamodb QueryInput中使用”BETWEEN”?

huangapple go评论104阅读模式
英文:

How to use "BETWEEN" in aws-sdk-go Dynamodb QueryInput?

问题

我正在使用aws-sdk-go来操作DynamoDB。我需要从我的数据库中收集一些项目。过滤条件是deviceid: xyz,time >= 10time <= 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 = &amp;dynamodb.QueryInput{
	TableName: aws.String(dbName),
	KeyConditions: map[string]*dynamodb.Condition{
		&quot;deviceid&quot;: {
			ComparisonOperator: aws.String(&quot;EQ&quot;),
			AttributeValueList: []*dynamodb.AttributeValue{
				{
					S: aws.String(&quot;xyz&quot;),
				},
			},
		},
		&quot;time&quot;: {
			ComparisonOperator: aws.String(&quot;BETWEEN&quot;),
			AttributeValueList: []*dynamodb.AttributeValue{
				{
					N: aws.String(&quot;10&quot;),
                    N: aws.String(&quot;20&quot;),
				},
			},

		},
	},
}

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:-

&quot;time&quot;: {
            ComparisonOperator: aws.String(&quot;BETWEEN&quot;),
            AttributeValueList: []*dynamodb.AttributeValue{
                {
                    N: aws.String(&quot;10&quot;),                        
                },
                {
                    N: aws.String(&quot;20&quot;),                        
                },
            },
        },

huangapple
  • 本文由 发表于 2016年11月2日 17:19:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/40376242.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定