0

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
Kristof
  • 1
  • 2
  • One thing that you need to change is to allow more results, i.e. remove or increase `Limit: 1`. Second thing is how do you want to actually query DynamoDB? If you are passing `room = 2` then 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. – iaforek Feb 21 '18 at 13:46
  • It was just an example on how i currently get the latest value of one room. My question is how to make a query that returns the last value of each room. So if i had a room 3 i need to get room 1, 2 and 3 with the latest value. – Kristof Feb 21 '18 at 13:52
  • Maybe this can help: https://stackoverflow.com/questions/12809295/nosql-getting-the-latest-values-from-tables-dynamodb-azure-table-storage – iaforek Feb 22 '18 at 11:52

0 Answers0