- DynamoDB Class Definition
- DynamoDB query cheat sheet
- So, all the logical operations that Dynamo supports for a query operations EQ | LE | LT | GE | GT | BEGINS_WITH | BETWEEN are only for fetching adjacent records , not random records.
- Search with null fields (attribute not defined)
- DynamoDB’s Global Secondary Indexes allow for the indexes to be sparse. That means that if you have a GSI whose hash or range key for an item is not defined then that item will simply not be included in the GSI. This is useful in a number of use cases as it allows you to directly identify records that contain certain fields. However, this approach will not work if you are looking for the lack of a field.
- can only use scan
- https://stackoverflow.com/questions/34349135/how-do-you-query-for-a-non-existent-null-attribute-in-dynamodb
- Example Search with Date Range:
{ TableName : "Movies", ProjectionExpression:"#yr, title, info.genres, info.actors[0]", KeyConditionExpression: "#yr = :yyyy and title between :letter1 and :letter2", ExpressionAttributeNames:{ "#yr": "year" }, ExpressionAttributeValues: { ":yyyy": 1992, ":letter1": "A", ":letter2": "L" } };
- API reference
- You must provide the name of the partition key attribute and a single value for that attribute. Query returns all items with that partition key value. Optionally, you can provide a sort key attribute and use a comparison operator to refine the search results.
- Use the
KeyConditionExpression
parameter to provide a specific value for the partition key. TheQuery
operation will return all of the items from the table or index with that partition key value. You can optionally narrow the scope of theQuery
operation by specifying a sort key value and a comparison operator inKeyConditionExpression
. To further refine theQuery
results, you can optionally provide aFilterExpression
. AFilterExpression
determines which items within the results should be returned to you. All of the other results are discarded.AQuery
operation always returns a result set. If no matching items are found, the result set will be empty. Queries that do not return results consume the minimum number of read capacity units for that type of read operation - Sort Order –
Query
results are always sorted by the sort key value. If the data type of the sort key is Number, the results are returned in numeric order; otherwise, the results are returned in order of UTF-8 bytes. By default, the sort order is ascending. To reverse the order, set theScanIndexForward
parameter to false. - limit – A single
Query
operation will read up to the maximum number of items set (if using theLimit
parameter) or a maximum of 1 MB of data and then apply any filtering to the results usingFilterExpression
. IfLastEvaluatedKey
is present in the response, you will need to paginate the result set. For more information, see Paginating the Results in the Amazon DynamoDB Developer Guide. FilterExpression
is applied after aQuery
finishes, but before the results are returned. AFilterExpression
cannot contain partition key or sort key attributes. You need to specify those attributes in theKeyConditionExpression
.- Troubleshooting
- dynamoDB index query does not return all data
- Results DataSet from DynamoDB Query using GSI is not returning correct results
- You reached the maximum number of items to evaluate (not necessarily the number of matching items). The limit is 1 MB.The response will contain a LastEvaluatedKey parameter, it is the last item’s id. You have to perform a new query with an extra ExclusiveStartKey parameter. (ExclusiveStartKey should be equal with LastEvaluatedKey’s value.)When the LastEvaluatedKey is empty you reached the end of the table.
- Nodjs cheat sheet