DynamoDB putItem ConditionExpression "boolean" true

csi*_*ilk 5 javascript amazon-web-services amazon-dynamodb

我正在尝试在 DynamoDB put 中执行 ConditionExpression 来检查存储的布尔值是否为 true(在本例中,用户是否已验证,请勿运行 put),我正在使用 javascript DocumentClient SDK(感谢 @shimon -tolts),代码如下:

var query = {
    TableName: tableName,
    Item: {
        email: email,
        verified: false,
        verifyToken: token
    },
    ConditionExpression: 'attribute_exists(email) AND verified = :bool',
    ExpressionAttributeValues: {
        ":bool":"false"
    }
};

dynamodb.put(query, function(err, data){
    if (err) return fn(err)
    fn(null, data);
});
Run Code Online (Sandbox Code Playgroud)

这是行不通的,无论调用什么,它都无法通过条件检查。

几乎是我需要的(伪代码):

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
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Shi*_*lts 4

我建议使用DocumentClient,因为它适用于 javascript 对象。要执行条件表达式,您必须指定 ExpressionAttributeNames 和 ExpressionAttributeValues,例如:

ConditionExpression: "#yr <> :yyyy and title <> :t",
ExpressionAttributeNames:{"#yr":"year"},
ExpressionAttributeValues:{
    ":yyyy":year,
    ":t":title
}
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看更多示例并在此处阅读更多内容