dynobase-icon
Dynobase

Error: DynamoDB FilterExpression Not Working

Rafal Wilinski

Answered by Rafal Wilinski

Last updated: October 23rd, 2026

Solution

FilterExpression is applied after DynamoDB reads a page, so an empty result can mean the current page had no matches rather than the entire query having none. Inspect Count, ScannedCount and LastEvaluatedKey.

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb";

const db = DynamoDBDocumentClient.from(new DynamoDBClient({}));

const page = await db.send(new QueryCommand({
  TableName: "Orders",
  KeyConditionExpression: "pk = :pk",
  FilterExpression: "#status = :status",
  ExpressionAttributeNames: { "#status": "status" },
  ExpressionAttributeValues: { ":pk": "CUSTOMER#123", ":status": "OPEN" },
}));
console.log(page.Items, page.LastEvaluatedKey);

For Query, put the queried partition and sort key constraints in KeyConditionExpression, not FilterExpression. Scan has no key condition and can filter key attributes. Compare stored types and exact values, including String versus Number and case differences, and define all aliases.

Follow LastEvaluatedKey even when Items is empty. Filters do not reduce read capacity already consumed. A GSI can filter only on attributes available in its projection; if the filter discards most items, consider an index that selects them by key.

See filter expressions and AWS documentation.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.