Kiksen
Kiksen

Reputation: 1777

Conditional update Dynamodb on nested object

I am trying to learn to use DynamoDB with C# I have Partial updates, Put, Delete working. Conditional update works (If the Attributes is part of root object).

I have the following model created.

enter image description here

Person with a lot of attributes. The following works:

Expression expr = new Expression();
expr.ExpressionStatement = "Age = :age";
expr.ExpressionAttributeValues[":age"] = 26;

UpdateItemOperationConfig config = new UpdateItemOperationConfig
{
    ConditionalExpression = expr,
    ReturnValues = ReturnValues.AllNewAttributes
};

Document updatedPerson2 = personCatalog.UpdateItem(doc, config);

But what if my condition was on the Pet Name?
I have tried a couple of approaches with no luck eg:

expr.ExpressionStatement = "Pet.Name = :name";
expr.ExpressionAttributeValues[":name"] = "Lilleper";

Hope someone can help :) Or just nudge me in the right direction.

Upvotes: 1

Views: 1891

Answers (1)

Alexander Patrikalakis
Alexander Patrikalakis

Reputation: 5195

Try externalizing the Name sub-attribute name to ExpressionAttributeNames.

Expression expr = new Expression();
expr.ExpressionStatement = "Pet.#name = :name";
expr.ExpressionAttributeNames["#name"] = "Name";
expr.ExpressionAttributeValues[":name"] = "Lilleper";

Upvotes: 2

Related Questions