A. The scan method is incorrect; it should be query
B. The table is empty, so no items are returned
C. Scan only returns items with a filter, so no filter means no items
D. Scan returns paginated results; you must handle LastEvaluatedKey to get all items
Solution
Step 1: Recognize Scan pagination behavior
Scan returns results in pages. If the table is large, it returns a subset and a LastEvaluatedKey to continue.
Step 2: Identify missing pagination handling
The code does not check for LastEvaluatedKey or continue scanning, so it only logs the first page.
Final Answer:
Scan returns paginated results; you must handle LastEvaluatedKey to get all items -> Option D
Quick Check:
Scan pagination needs LastEvaluatedKey handling = D [OK]
Hint: Handle LastEvaluatedKey to get all Scan results [OK]
Common Mistakes:
Assuming Scan returns all items in one call
Confusing Scan with Query filters
Using query() instead of scan()
5. You want to find all items where the attribute 'status' equals 'active' in a large DynamoDB table. Why might using Scan be inefficient, and what is a better approach?
hard
A. Scan reads the entire table which is slow; better to use Query with a Global Secondary Index on 'status'
B. Scan only reads matching items quickly; no better approach needed
C. Scan automatically uses indexes; Query is slower for this case
D. Scan updates items with 'status'='active'; Query deletes them
Solution
Step 1: Understand Scan inefficiency
Scan reads every item in the table, which is slow and costly for large tables.
Step 2: Use Query with indexes
Creating a Global Secondary Index on 'status' allows Query to quickly find items where 'status'='active' without scanning all items.
Final Answer:
Scan reads the entire table which is slow; better to use Query with a Global Secondary Index on 'status' -> Option A
Quick Check:
Use Query with index, not Scan for filtering = C [OK]
Hint: Use Query with index, not Scan, for filtered searches [OK]