aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.08k stars 576 forks source link

'KeyConditionExpression' not working V3 #1961

Closed brmur closed 3 years ago

brmur commented 3 years ago

Describe the bug The "Scanning" example below uses a 'KeyConditionExpression'. But I had to move my key filter to the 'FilterExpression' to get it to work. Was this changed in v3 since technically with a scan you are getting no benefit from the key, so it's more consistent to simply put all filters in the FilterExpression (including any for key attributes).

// Import required AWS SDK clients and commands for Node.js
const { DynamoDBClient, ScanCommand } = require("@aws-sdk/client-dynamodb");
const REGION = "eu-west-1";

// Set parameters
const params = {
    KeyConditionExpression: "Subtitle = :topic",
    FilterExpression: "contains (Subtitle, :topic)",
    ExpressionAttributeValues: {
        ":topic": { S: "Sub" },
    },
    ProjectionExpression: "Season, Episode, Title, Subtitle",
    TableName: "EPISODES_TABLE",
};

// Create DynamoDB service object
const dbclient = new DynamoDBClient({ region: REGION });

async function run() {
    try {
        const data = await dbclient.send(new ScanCommand(params));
        data.Items.forEach(function (element, index, array) {
            console.log(element.Title.S + " (" + element.Subtitle.S + ")");
        });
    } catch (err) {
        console.log("Error", err);
    }
}
run();

SDK version number @aws-sdk/client-dyanamodb@3.3.0

Is the issue in the browser/Node.js/ReactNative? Node.js

Details of the browser/Node.js/ReactNative version Paste output of npx envinfo --browsers or node -v or react-native -v

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here. See http://docs.aws.amazon.com/en_us/sdk-for-javascript/v3/developer-guide/dynamodb-example-query-scan.html for example, and SDK code examples to quickly create this table for testing.

brmur commented 3 years ago

submitted on behalf of customer

brmur commented 3 years ago

'KeyConditionExpression' works with Query, not Scan, as expected, so closing

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.