Monday, May 20, 2024
117
rated 0 times [  121] [ 4]  / answers: 1 / hits: 50670  / 7 Years ago, thu, july 20, 2017, 12:00:00

I have a table with partition key and sort key also 2 other columns. I am unable to get items using FilterExpression for multiple conditions with AND in DynamoDB using javaScript AWS SDK. Can anyone provide correct code to retrieve data with multiple conditions in FilterExpression?
My code is as follows:


var params = {
TableName: 'Department',
KeyConditionExpression: '#company = :companyId'
, ExpressionAttributeNames: {
'#company': 'CompanyID',
'#dType': 'DepartmentType',
'#cTime': 'CreatedTime'
}
, ExpressionAttributeValues: {
':companyId': 'Test',
':deptType': dType,
':daysPrior': 1250456879634
},FilterExpression: '#dType = :deptType AND #ts > :daysPrior'
};

More From » amazon-dynamodb

 Answers
4

There is typo error in the format in your query(after CreatedTime)
To keep it clean, use either double quotes or single quotes but not both.
I have used double quotes, just the way aws sample codes are there.


var params = {
TableName: "Department",
KeyConditionExpression: "#company = :companyId",
ExpressionAttributeNames: {
"#company": "CompanyID",
"#dType": "DepartmentType",
"#cTime": "CreatedTime" //here
},
ExpressionAttributeValues: {
":companyId": "Test",
":deptType": dType,
":daysPrior": 1250456879634
},
FilterExpression: "#dType = :deptType AND #cTime > :daysPrior"
};

[#57021] Tuesday, July 18, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jennie

Total Points: 593
Total Questions: 102
Total Answers: 106

Location: Federated States of Micronesia
Member since Fri, Sep 16, 2022
2 Years ago
jennie questions
;