英文:
Golang get item per attibute phone dynamodb
问题
我正在查询 DynamoDB 中的一个值,但是我收到了错误消息 "提供的键元素与模式不匹配"。
params := &dynamodb.GetItemInput{
    Key: map[string]*dynamodb.AttributeValue{
        "phone": { // 必填项
            S: aws.String(phone),
        },
    },
    TableName: aws.String(TableName),
}
请注意,你需要将 phone 替换为你要查询的电话号码,并将 TableName 替换为你的表名。
英文:
I am querying a value in dynamodb but I get the error "The supplied key element does not match the schema".
{
  "id": {
    "S": "c8f8fd5d-a483-4a4e-8adf-75c4134678cc"
  },
  "phone": {
    "S": "+57308394111288"
  },
 }
Golang
params := &dynamodb.GetItemInput{
		Key: map[string]*dynamodb.AttributeValue{
			"phone": { // Required
				S: aws.String(phone),
			},
		},
		TableName: aws.String(TableName),
}
答案1
得分: 1
感谢您的消息。解决方法如下:
	filt := expression.Name("phone").Equal(expression.Value(phone))
	expr, err := expression.NewBuilder().WithFilter(filt).Build()
	params := &dynamodb.ScanInput{
		ExpressionAttributeNames:  expr.Names(),
		ExpressionAttributeValues: expr.Values(),
		FilterExpression:          expr.Filter(),
		ProjectionExpression:      expr.Projection(),
		TableName:                 aws.String(tableName),
	}
英文:
thanks per messages.solved this way
	filt := expression.Name("phone").Equal(expression.Value(phone))
	expr, err := expression.NewBuilder().WithFilter(filt).Build()
	params := &dynamodb.ScanInput{
		ExpressionAttributeNames:  expr.Names(),
		ExpressionAttributeValues: expr.Values(),
		FilterExpression:          expr.Filter(),
		ProjectionExpression:      expr.Projection(),
		TableName:                 aws.String(tableName),
	}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论