I have to get the latest temperature from each distinct room
room time temp
1 10:05:00 20
2 10:05:00 21
1 10:10:00 22
2 10:10:00 23
1 10:15:00 24
2 10:15:00 25
I know how to get the latest value from one room. Following code returns the latest value of room 2.
var params = {
TableName: "rooms",
KeyConditionExpression: "#room = :room",
ExpressionAttributeNames:{
"#room": "room"
},
ExpressionAttributeValues: {
":room":2
},
ScanIndexForward : false,
Limit: 1
};
Here i do get:
room time temp
2 10:15:00 25
But what i need to get is:
room time temp
1 10:15:00 24
2 10:15:00 25
Limit: 1. Second thing is how do you want to actually query DynamoDB? If you are passingroom = 2then how do you expect to get room 1? Do you want to get simply the latest time for all rooms or do you want to query DB and specify which rooms you are interested in. Lastly, save your self and do it in any SQL DB. It is so much simpler to query data. DynamoDB has a lot of restrictions and limits. Sooner or later you will find more problems with DynamoDB.