Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda