DEV Community

Abhishek Gupta for AWS

Posted on • Originally published at community.aws

2

[20 Days of DynamoDB] Day 10 - Query API with Filter Expression

Posted: 19/Jan/2024

With the DynamoDB Query API, you can use Filter Expressions to discard specific query results based on a criteria. Note that the filter expression is applied after a Query finishes, but before the results are returned. Thus, it has no impact on the RCUs (read capacity unit) consumed by the query.

Here is an example that filters out forum discussion threads that have less than a specific number of views:

    resp, err := client.Query(context.Background(), &dynamodb.QueryInput{
        TableName:              aws.String(tableName),
        KeyConditionExpression: aws.String("ForumName = :name"),
        FilterExpression:       aws.String("#v >= :num"),
        ExpressionAttributeNames: map[string]string{
            "#v": "Views",
        },
        ExpressionAttributeValues: map[string]types.AttributeValue{
            ":name": &types.AttributeValueMemberS{Value: forumName},
            ":num":  &types.AttributeValueMemberN{Value: numViews},
        },
    })
Enter fullscreen mode Exit fullscreen mode

Recommended reading: Filter Expressions

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay