0

I have something like this on Dynamo:

{
    "mail": "[email protected]",
    "data": {
        "type": 1
    }
}

I have an index on "mail" attribute and I'm trying to query over all data found with an specified mail filtering the attribute "data". Something like this:

const params = {
    TableName: 'tableName',
    IndexName: "mail_index",
    KeyConditionExpression: "#mail = :mail",
    FilterExpression: '#status = :val',
    ExpressionAttributeNames: {
        '#mail': 'mail',
        '#status': 'data.type'
    },
    ExpressionAttributeValues: {
        ':mail': '[email protected]',
        ':val': {N: 5}
    } 
};

dynamoDoc.query(params, (err, data) => {
    console.log(data);
});

But I'm always getting an empty result. What am I doing wrong?

1 Answer 1

2

Try this:

const params = {
    TableName: 'tableName',
    IndexName: "mail_index",
    KeyConditionExpression: "#mail = :mail",
    FilterExpression: '#data.#type = :val',
    ExpressionAttributeNames: {
        '#mail': 'mail',
        '#data': 'data',
        '#type': 'type'
    },
    ExpressionAttributeValues: {
        ':mail': '[email protected]',
        ':val': {N: 5}
    } 
};

Because both data and type are reserved words, DynamoDB needs both of them to be escaped.

Sign up to request clarification or add additional context in comments.

1 Comment

Thx! Worked for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.