1

I have a requirement to query the dynamoDB and get all the records which matches a certain criteria. The requirement is, I have table say parent_child_table, which has parent_id and child_id as two columns, now i need to query the table with a particular input id and fetch all the records. for Example

enter image description here

now if I query the db with id 67899, the I should get both two records i.e 12345 and 67899.

I was trying to use below methods :

  1. GetItemRequest itemRequest=new GetItemRequest().withTableName("PARENT_CHILD_TABLE").withKey(partitionKey.entrySet().iterator().next(), sortKey.entrySet().iterator().next());

but am not getting OR operator.

1 Answer 1

1

DynamoDB doesn't work like that...

GetItemRequest() can only return a single record.

Query() can return multiple records, but only if you are using a composite primary key (partition key + sort key) and you can only query within a single partition...so all the records to be returned must have the same partition key.

Scan() can return multiple records from any partition, but it does so by always scanning the entire table. Regular use of scan is a bad idea.

Without knowing more it's hard to provide guidance, but consider a schema like so:

partition key  sort key
12345          12345
12345          12345#67899
12345          12345#67899#97765

Possibly adding some sort of level indicator in the sort key or just as an attribute.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.