我正在尝试在 DynamoDB put 中执行 ConditionExpression 以检查存储的 bool 值是否为真(在此示例中,用户是否已经过验证不要运行 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);
});
这是行不通的,无论调用什么,它都无法通过条件检查。
几乎是我需要的(伪代码):
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
有什么想法吗?
最佳答案
我建议使用 DocumentClient因为它适用于 javascript 对象。 要执行条件表达式,您必须指定 ExpressionAttributeNames 和 ExpressionAttributeValues 例如::
ConditionExpression: "#yr <> :yyyy and title <> :t",
ExpressionAttributeNames:{"#yr":"year"},
ExpressionAttributeValues:{
":yyyy":year,
":t":title
}
关于javascript - DynamoDB putItem ConditionExpression "boolean"真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36441987/