Given a DynamoDB table using the adjacency list pattern where each item has a NodeId and a ParentId, which query will return all direct children of the node with NodeId = 'A1'?
Table: Nodes
Attributes: NodeId (PK), ParentId
Sample data:
{NodeId: 'A1', ParentId: null}
{NodeId: 'B1', ParentId: 'A1'}
{NodeId: 'B2', ParentId: 'A1'}
{NodeId: 'C1', ParentId: 'B1'}Remember that in DynamoDB, Query works only on the partition key. If ParentId is not the partition key, you cannot query by it directly.
Since ParentId is not the partition key, you cannot use Query to find children by ParentId. You must use Scan with a FilterExpression to find all items where ParentId equals 'A1'.
In the adjacency list pattern, how is the parent-child relationship typically represented in a DynamoDB table?
Think about how you can find a node's parent or children by looking at attributes.
The adjacency list pattern stores each node with its own unique NodeId and a ParentId attribute pointing to its parent node. This allows traversal up and down the tree.
Which option contains a syntax error in the DynamoDB query expression to find children nodes?
Query parameters example:
{
TableName: 'Nodes',
KeyConditionExpression: 'ParentId = :pid',
ExpressionAttributeValues: { ':pid': 'A1' }
}Check the operator used in the KeyConditionExpression.
DynamoDB expressions use a single equals sign '=' for comparison, not '=='. Using '==' causes a syntax error.
You want to efficiently query all children of a node by ParentId in DynamoDB. Which table design improves query performance?
Think about which key allows you to query all children by parent efficiently.
Using ParentId as the partition key allows you to Query all items with that ParentId quickly. NodeId as sort key uniquely identifies children.
A developer tries to recursively fetch all descendants of a node by repeatedly querying children using ParentId. The code runs but returns incomplete results. What is the most likely cause?
Consider DynamoDB limits on query results and how to handle large datasets.
DynamoDB Query returns a maximum of 1MB of data per call. If there are more children, the developer must use pagination with LastEvaluatedKey to fetch all results.