'How to use where in condition in dynamodb filterexpression
I am learning dynamodb and I am trying how to fetch items with status 0 and 1 but when i write the below query, it is throwing error "Error ValidationException: Invalid FilterExpression: Syntax error; token: ":user_status_val", near: "IN :user_status_val". Could any one please help in fixing this issue.
const checkUserExists = (req) => {
return new Promise((resolve,reject) =>{
var searchParams = {};
if(req.body.email != ""){
searchParams = {
FilterExpression : "#email = :e AND #user_status IN :user_status_val",
ExpressionAttributeNames: {
"#user_status": "status",
"#email" : "email",
},
ExpressionAttributeValues: {
':user_status_val' : req.body.status,
':e' : req.body.email,
},
}
}
var params = {
Select: "COUNT",
TableName: 'register'
};
var finalParams = {...searchParams, ...params}
DynamoDB.scan(finalParams, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log(data);
//res.send(data);
return resolve(data);
}
});
});
}
Solution 1:[1]
(As I was about to submit the question, I was tagging, and found the answer. I think it is worthwhile to document it here so others can easily find it.)
Define __rmul__(self, other). This stands for right-multiply. When the object on the left fails to multiply (in the example above the integer doesn't know how to multiply the Point class on the right) Python will look at the object on the right to see if the __rmul__(self, other) special method is defined, and does it work? If it does, it will use this implementation instead.
For classes that are commutative (i.e. you can multiply either AB or BA and get the same results) you can define it as:
def __mul__(self, other):
if isinstance(other, Point):
x = self.x * other.x
y = self.y * other.y
return Point(x, y)
elif isinstance(other, int):
x = self.x * other
y = self.y * other
return Point(x, y)
def __rmul__(self, other):
return self.__mul__(other)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | boymeetscode |
