The DynamoDB Query operation retrieves multiple items that share a partition-key value. A table must use a partition key and sort key to return a collection of items; the partition key identifies the group, while the sort key orders items within it. section 12.4.2 section 12.15
Build a query around key conditions, then refine or paginate the result:
- Use FilterExpression for attributes that are not keys, such as task category or due date. DynamoDB applies the filter after inspecting every item returned by the key condition, so filtering does not use an index. section 12.4.2
- Query a global secondary index when the required access pattern uses another partition key, such as category, instead of the table's uid key. section 12.4.4
Listing Emma's tasks
A task listing queries todo-task with KeyConditionExpression set to uid = :uid, optionally adds a sort-key continuation value, and filters for overdue or due-today tasks. The command node index.js task-ls emma shopping demonstrates the surrounding application use case.
Query is efficient for known key access patterns, while Scan searches every table item and is less efficient. Strongly consistent reads can avoid stale data, but reads from global secondary indexes are always eventually consistent. section 12.15
