问题
How to Query array of objects(workingDays) key containing only "Tue" in dynamoDb with Scan Operation,I have queried using filter Expression but i am getting no results.
var queryData = {
TableName: tableName,
FilterExpression: "contains (workingDays, :dayVal)",
ExpressionAttributeValues: {
":dayVal": {
S:"Tue"
}
}
};
console.log("getParams ==>", queryData)
dynamodb.scan(queryData, function (err, details) {
if (err) {
console.log(err, err.stack); // an error occurred
callback(err, null)
}
else{
callback(null, details)
}
})
回答1:
ExpressionAttributeValues in your query contains String ["S"] as 'key' for value 'Tue', where as in your table, 'workingDays' is a list of map object containing value for day keys.
Try below code:
var queryData = {
TableName: tableName,
ExpressionAttributeNames: {
"#workingDays": "workingDays",
},
FilterExpression: "contains (#workingDays, :dayVal)",
ExpressionAttributeValues: {
":dayVal": {
"day":"Tue"
}
}
};
console.log("getParams ==>", queryData)
docClient.scan(queryData, function (err, details) {
if (err) {
console.log(err, err.stack); // an error occurred
// callback(err, null)
}
else{
// callback(null, details)
console.log(details);
}
});
来源:https://stackoverflow.com/questions/54002458/how-to-query-a-array-of-objects-in-dynamodb-using-filterexpression-in-scan-opera