Reputation: 103
I want to scan DynamoDB to get records with price between 9 and 13. My code:
ar AWS = require('aws-sdk');
var db = new AWS.DynamoDB();
exports.handler = function(event, context) {
var params = {
TableName: "StreamsLambdaTable",
ProjectionExpression: "price", //specifies the attributes you want in the scan result.
FilterExpression: "price between :lower and :higher",
// ExpressionAttributeNames: {
// "#yr": "year",
// },
ExpressionAttributeValues: {
":lower": 9,
":higher": {"N": 13}
}
};
db.scan(params, function(err, data) {
if (err) {
console.log(err); // an error occurred
}
else {
console.log(data.Item.name.S); // successful response
context.done(null,{"Result": "Operation succeeded."});
//res.send(data.name);
}
// return next();
});
};
But I've got 2 errors:
I tried two difffrent approaches (as you can see in the code:)
ExpressionAttributeValues: {
":lower": 9,
":higher": {"N": 13}
}
but neither of them work.
EDIT:
I've got another problem. I want to get all those prices. I tried with that code:
data.Items.forEach(function(record) {
console.log(
record.price + " dadada");
});
But I get:
2016-06-14T20:33:23.915Z 3ce248c7-326f-11e6-855c-57839aedb817 [object Object] dadada
2016-06-14T20:33:23.915Z 3ce248c7-326f-11e6-855c-57839aedb817 [object Object] dadada
EDIT 2:
Soolved. Just changed record.price to record.price.N
Upvotes: 0
Views: 2711
Reputation: 200562
The error messages are telling you exactly what is wrong. It expects ":lower
" to be a structure, just like you have provided to ":higher"
, and it expects the value of ":higher"
to be a string. Like so:
ExpressionAttributeValues: {
":lower": {"N": "9"},
":higher": {"N": "13"}
}
Upvotes: 2