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

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

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

问题

我正在使用aws-sdk-go来操作DynamoDB。我需要从我的数据库中收集一些项目。过滤条件是deviceid: xyz,time >= 10time <= 20

time是我的数据库的排序键,deviceid是主键。我理解我需要使用BETWEEN来实现我的目标。我的实现不成功,如下所示:

  1. var queryInput = &dynamodb.QueryInput{
  2. TableName: aws.String(dbName),
  3. KeyConditions: map[string]*dynamodb.Condition{
  4. "deviceid": {
  5. ComparisonOperator: aws.String("EQ"),
  6. AttributeValueList: []*dynamodb.AttributeValue{
  7. {
  8. S: aws.String("xyz"),
  9. },
  10. },
  11. },
  12. "time": {
  13. ComparisonOperator: aws.String("BETWEEN"),
  14. AttributeValueList: []*dynamodb.AttributeValue{
  15. {
  16. N: aws.String("10"),
  17. },
  18. {
  19. N: aws.String("20"),
  20. },
  21. },
  22. },
  23. },
  24. }

这里有哪些错误?

英文:

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:

  1. var queryInput = &amp;dynamodb.QueryInput{
  2. TableName: aws.String(dbName),
  3. KeyConditions: map[string]*dynamodb.Condition{
  4. &quot;deviceid&quot;: {
  5. ComparisonOperator: aws.String(&quot;EQ&quot;),
  6. AttributeValueList: []*dynamodb.AttributeValue{
  7. {
  8. S: aws.String(&quot;xyz&quot;),
  9. },
  10. },
  11. },
  12. &quot;time&quot;: {
  13. ComparisonOperator: aws.String(&quot;BETWEEN&quot;),
  14. AttributeValueList: []*dynamodb.AttributeValue{
  15. {
  16. N: aws.String(&quot;10&quot;),
  17. N: aws.String(&quot;20&quot;),
  18. },
  19. },
  20. },
  21. },
  22. }

What are the mistakes I made here?

答案1

得分: 5

"time"的值应按照以下方式给出:

  1. "time": {
  2. ComparisonOperator: aws.String("BETWEEN"),
  3. AttributeValueList: []*dynamodb.AttributeValue{
  4. {
  5. N: aws.String("10"),
  6. },
  7. {
  8. N: aws.String("20"),
  9. },
  10. },
  11. },
英文:

The time value should be given as mentioned below:-

  1. &quot;time&quot;: {
  2. ComparisonOperator: aws.String(&quot;BETWEEN&quot;),
  3. AttributeValueList: []*dynamodb.AttributeValue{
  4. {
  5. N: aws.String(&quot;10&quot;),
  6. },
  7. {
  8. N: aws.String(&quot;20&quot;),
  9. },
  10. },
  11. },

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:

确定