dongyi1429 2019-04-20 20:40
浏览 93
已采纳

在Dynamo DB中查询索引

I need an example in Go on how to do a query on an index in dynamo db. For JavaScript I found this one: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SQLtoNoSQL.Indexes.QueryAndScan.html

I could not find one for Go. I tried this:

    // Here "user_id" is the key, and
    // "user_id_index" is the secondary index

    keyCondition := expression.Key("user_id").Equal(expression.Value(userId))
    expr, errExpression := expression.NewBuilder().WithKeyCondition(keyCondition).WithProjection(proj).Build()

    if errExpression != nil {
        log.Printf("error: creating dynamo expression ", errExpression)

        return listResponse, errExpression
    }
    params := &dynamodb.QueryInput{
        ExpressionAttributeValues: expr.Values(),
        ProjectionExpression:      expr.Projection(),
        TableName:                 aws.String(tableName),
        IndexName:                 aws.String("user_id_index"),
        KeyConditionExpression:    expr.KeyCondition(),

    }
    result, errResults := svc.Query(params)

I get the following error:

error: scanning dynamo table %!(EXTRA *awserr.requestError=ValidationException:
 Invalid KeyConditionExpression: An expression attribute name used in the document path is not defined;
 attribute name: #0

Any link to a good tutorial would be appreciated, or code example as an answer too.

  • 写回答

1条回答 默认 最新

  • dov6891 2019-04-20 21:46
    关注

    I think you're missing expression attribute names. Try adding this to your query input:

    ExpressionAttributeNames:  expr.Names(),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器