Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
Sorting by partition key/sort key does not work

I'm working on an IoT project where I need to read some data from a device. I use AWS, and I'm currently working on some lambda function code. But I can't figure out how to get the last (newest) item from my database.

My database has two keys:

Partition key: device_id (Number)

Sort key sample_time (Number)

This is a part of the code I wrote to retrieve the newest reading from my IoT device

case "GET /data/newest":
        body = await dynamo
            .query({ 
              TableName: "bikelock_db",
              KeyConditionExpression: 'device_id = :id',
              ExpressionAttributeValues: {
                ":id": 1,
              },
              Limit: 1,
              ScanForwardIndex: false,
            })
            .promise();
        break;

This code however, only returns the first added item from the database. Changing the ScanForwardIndex: false to true doesn't change a thing. I thought the Sort Key would sort it automatically, but it does not.

Any idea what I'm missing, or why it isn't working?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try ScanIndexForward and I bet it'll work. You transposed the two words.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!