I have a table in DynamoDB and have partition key and a sort key. For example, the table structure is as follows.
// Primary Keys
id -> PK
name -> SK
Info -> json Formatted Attributes
So let's say there are two items in the table,
// Item 1
{
id: 10245-25-45,
name: "Name 1",
info: {
userId: 1012, // PK
userName: "ABC", // SK
type: "type 1",
date: "2020-01-03 04:05:12"
}
}
// Item 2
{
id: 10245-65-70, // pK
name: "Name 2", // SK
info: {
userId: 1013,
userName: "ABCD",
type: "type 2",
date: "2020-01-03 04:10:12"
}
}
I am using Java
as the language and using DynamoDBMapper
to do CRUD operations. So I know I can use DynamoDBMapper.load()
to get one item by providing PK
and SK
,
but I was wondering how to get data by searching non-key attributes. For example, I need to get One Item at a time by providing,
// userId, userName, type, data are unique values so it will give only one record if exists
find item by userId;
find item by userId and userName;
find item by type and date;
So above are some of my access patterns and basically, I need to get data without providing PK and SK and also I can't use global secondary indexes. So I know there is Query. but I am wondering without that is there any way to do what I need? I really appreciate it if anybody can help me. Thanks in advance.