Introduction
Hierarchical data modeling helps organize data that has parent-child relationships, like folders and files, in a way that is easy to find and use.
Use a primary key (partition key) for the top-level item. Use a sort key to represent the hierarchy, often by combining parent and child IDs or using a path-like string. Example: PartitionKey: 'Category#1' SortKey: 'SubCategory#1'
PartitionKey: 'Folder#A' SortKey: 'File#1'
PartitionKey: 'Org#123' SortKey: 'Dept#456#Team#789'
PartitionKey: 'Post#100' SortKey: 'Comment#200'
CREATE TABLE Hierarchy ( PK STRING, SK STRING, Data STRING, PRIMARY KEY (PK, SK) ); -- Insert a folder INSERT INTO Hierarchy (PK, SK, Data) VALUES ('Folder#A', 'Metadata', 'Folder A info'); -- Insert files inside folder INSERT INTO Hierarchy (PK, SK, Data) VALUES ('Folder#A', 'File#1', 'File 1 content'); INSERT INTO Hierarchy (PK, SK, Data) VALUES ('Folder#A', 'File#2', 'File 2 content'); -- Query all items in Folder A SELECT * FROM Hierarchy WHERE PK = 'Folder#A';
ParentID and sort key ChildID, what will the query KeyConditionExpression: ParentID = 'P1' return?KeyConditionExpression: ParentID = :pid AND ChildID = :cid. It returns only one child instead of all children. What is the mistake?ChildID = :cid restricts results to one specific child.begins_with or omit ChildID condition.Pass the test and this pattern moves unknown