csilk
csilk

Reputation: 2932

DynamoDB DocumentClient ConditionExpression - If Statement

Wondering if there is any way to write a ConditionExpresson If statement on a Put, a pseudocode example of what i'm looking for:

IF email already exists AND verified equals false 
   THEN allow PUT
IF email already exists AND verified equals true
   THEN don't allow PUT
IF email does not exist
   THEN allow PUT

Cheers

Upvotes: 1

Views: 1353

Answers (1)

csilk
csilk

Reputation: 2932

Ended up figuring it out in a more elegant way:

query.Item = {
    email: email,
    verified: false,
    verifyToken: token
};

query.ExpressionAttributeNames = {
    '#verified' : 'verified'
};

query.ExpressionAttributeValues = {
    ':false' : false,
};

query.ConditionExpression = '#verified = :false OR attribute_not_exists(verified)';

Upvotes: 1

Related Questions