Error: dynamodb query not returning the full item
![Rafal Wilinski](https://pbs.twimg.com/profile_images/1390706809548197895/SVCKpLNE_400x400.png)
Answered by Rafal Wilinski
What's Causing This Error
This error arises due to two reasons:
1. Due to GSI
If you are querying a GSI of a table, you will only get the attributes you project onto the index. It may cause a partial item to get returned.
2. Due to Projection Expressions
The "Projection Expression" is a string that identifies the attributes DynamoDB should return for an item in a query. Based on this definition, DynamoDB will not return the entire item if you specify only a limited number of attributes.
Solution - Here's How To Resolve It
Try the following and see which works for you to resolve this error.
1. Resolving the GSI
If you are using a GSI, ensure that you project all the item's attributes into the index. For example, select Attributes Projections as "All" when creating the index to project all the attributes.
However, this is not recommended as DynamoDB will update your indexes every time an item in the table updates, increasing your DynamoDB bill.
![dynamodb query not returning the full item](/images/errors/dynamodb-query-not-returning-the-full-item.png)
Figure - Projection all the attributes into the index
2. Resolving the Projection Expressions
Simply removing the Projection Expression from your query will ensure that DynamoDB returns the entire item from the query. You may use the snippet shown below as a reference.
const documentClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'}); await documentClient.query({ TableName: 'Table', IndexName: 'Index', // optional KeyConditionExpression: 'HashKey = :hkey', ExpressionAttributeValues: { ':hkey': 'key', } }).promise();
Other Common DynamoDB Errors (with Solutions)
- dynamodb the table does not have the specified index
- ProvisionedThroughputExceededException DynamoDB
- dynamodb atomic counter not working
- DynamoDB Query Limit Not Working
- aws.dynamodb.documentclient is not a constructor
- DynamoDB Delete Not Working
- DynamoDB Is Unsupported It Cannot Be Instantiated
- ValidationException: Invalid KeyConditionExpression: Attribute name is a reserved keyword;
- DynamoDB Local NoClassDefFoundError
- DynamoDB failedbatch retry
- ImportError: No module named boto3 (DynamoDB)
- appsync dynamodb not seeing all fields
- cannot find module 'dynamodb-doc'
- dynamodb cannot read property 'push' of undefined