英文:
how to get the records using partition key from a composite primary key in dynamodb
问题
插入代码
Item item_to_insert = new Item().withPrimaryKey("LatLong", key, "location_code", key)
.withJSON("location_address", jsonW.toString())
.withString("version", "1");
PutItemOutcome outcome = table.putItem(item_to_insert);
检索
GetItemSpec i_spec = new GetItemSpec()
.withPrimaryKey("LatLong", key, "location_code", key)
.withProjectionExpression("location_address")
.withConsistentRead(true);
现在我想仅使用分区键 LatLong 属性检索记录。有任何方法可以做到这一点吗?
英文:
I am using java to insert and retrieve records in DynamoDB.
Insertion Code
Item item_to_insert = new Item().withPrimaryKey("LatLong", key,"location_code",key)
.withJSON("location_address", jsonW.toString())
.withString("version","1");
PutItemOutcome outcome = table.putItem(item_to_insert);
Retrieving
GetItemSpec i_spec = new GetItemSpec()
.withPrimaryKey("LatLong", key,"location_code",key)
.withProjectionExpression("location_address")
.withConsistentRead(true);
Now I want to retrieve the records just using LatLong attribute which is partition key. Any Idea how to do this??
答案1
得分: 1
GetItem 获取特定项目,需要您指定完整的主键。如果您想检索所有具有共同分区键的项目,我认为您要找的方法是 Query 方法。
在此处查看更多信息:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryingJavaDocumentAPI.html
代码将类似于以下内容:
QuerySpec spec = new QuerySpec()
.withKeyConditionExpression("Id = :v_id")
.withValueMap(new ValueMap()
.withString(":v_id", "Amazon DynamoDB#DynamoDB Thread 1"));
英文:
GetItem fetches a specific item, which requires you to specify the complete primary key. If you want to retrieve all items with a common partition key, I believe the method you're looking for is the Query method.
See more here: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryingJavaDocumentAPI.html
The code would look something like this:
QuerySpec spec = new QuerySpec()
.withKeyConditionExpression("Id = :v_id")
.withValueMap(new ValueMap()
.withString(":v_id", "Amazon DynamoDB#DynamoDB Thread 1"));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论