1

I am trying to update a specific list entry using a counter.

 const taskParams = {
        TableName: CONST.NAMES.SUJET_TABLE_NAME,
        Key: {
            id: defectId
        },
        UpdateExpression: "SET #list.#epicType.#tasks[#taskIndex].#tracking =:attrValue ",
        ExpressionAttributeNames: {
            '#list': 'epicsList',
            '#tasks': 'tasks',
            '#epicType': epicType,
            '#taskIndex': taskCounter,
            '#tracking': 'tracking',

        },
        ExpressionAttributeValues: {
            ':attrValue': epicData["tasks"][0]["tracking"],
        },
    };

    try {
        await documentClient.update(taskParams).promise();
        console.log("Task successfully created.")

    } catch (err) {
        console.log("Unable to create Task ", err);
    }

Here is a sample of the database entry

When executing I get the following error :

ValidationException: Invalid UpdateExpression: Syntax error; token: "#taskIndex", near: "[#taskIndex]"

Is the syntax wrong or is there something else I am not aware of?

2
  • another option, though I don't know your access patterns, is to model your data differently. You could have a sort key on each item that is a concatenated key and use the begins_with() expression when querying. So you have a sort key like epic::DEV::tasks and so on. I say this as I can forsee these documents getting quite large and if you broke them up, you'd be updating only the slice of data that you need to. When you need all of the data, you can still do a begins_with("epic::DEV") and that'd get all of the items for that defect. Commented Dec 23, 2021 at 16:35
  • Thank you for your suggestion. I agree that the data model is neither optimized nor ideal. Unfortunately, the schema was put in place by someone else and my only job is to implement the back end fonctionalities. Commented Dec 25, 2021 at 15:04

1 Answer 1

1

I finally found the answer, for those who are having trouble with this :

 const taskParams = {
        TableName: CONST.NAMES.SUJET_TABLE_NAME,
        Key: {
            id: defectId
        },
        UpdateExpression: "SET #list.#epicType.#tasks[" + taskIndex+ "].#tracking =:attrValue ",
        ExpressionAttributeNames: {
            '#list': 'epicsList',
            '#tasks': 'tasks',
            '#epicType': epicType,
            '#tracking': 'tracking',

        },
        ExpressionAttributeValues: {
            ':attrValue': epicData["tasks"][0]["tracking"],
        },
    };
Sign up to request clarification or add additional context in comments.

Comments

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.