Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda