1

I have this table that has this line on it as you can see below:

id,"data_dia","nome_completo","nome_produto","nome_tuna","numero_socio","preco_quantidade","quantidade","tipo","valor_conta","valor_pagamento"
compra_pagamento,"2024-11-09T01:26:57.748Z","","chupa chups","joker","177","0.4","1","compra","'-0.40","null"

As I run this code the table returns the line properly

const params = {
      TableName: 'HISTORICO-teste',
      KeyConditionExpression: 'id = :id AND data_dia BETWEEN :data_inicial AND :data_final',
      ScanIndexForward: false,
      FilterExpression: '#nome_tuna = :nome_tuna',
      ExpressionAttributeNames: { '#nome_tuna': 'nome_tuna' },
      ExpressionAttributeValues: {
          ':data_inicial': '2024-08-07T00:00:00.000Z',
          ':data_final':   '2025-07-08T23:59:59.999Z',
          ':nome_tuna': 'joker',
          ':id': 'compra_pagamento'
      }
    }

await dynamo.query(params).then(result => {
  console.log(result.Items);
});

But if I change the code to reflect a data greater then the one above it doesn't return the line
soo if for example, I change the
':data_final': '2025-07-08T23:59:59.999Z'

START RequestId: 8a743c09-4f50-44d3-bbac-6e0bdfcebf5b Version: $LATEST
2025-07-16T15:28:10.330Z    8a743c09-4f50-44d3-bbac-6e0bdfcebf5b    INFO    2024-08-07T00:00:00.000Z
2025-07-16T15:28:10.330Z    8a743c09-4f50-44d3-bbac-6e0bdfcebf5b    INFO    2025-07-08T23:59:59.999Z
2025-07-16T15:28:10.430Z    8a743c09-4f50-44d3-bbac-6e0bdfcebf5b    INFO    [
  {
    nome_produto: 'chupa chups',
    tipo: 'compra',
    data_dia: '2024-11-09T01:26:57.748Z',
    valor_pagamento: null,
    valor_conta: '-0.40',
    numero_socio: 177,
    quantidade: 1,
    id: 'compra_pagamento',
    nome_tuna: 'joker',
    nome_completo: '',
    preco_quantidade: 0.4
  }
]
END RequestId: 8a743c09-4f50-44d3-bbac-6e0bdfcebf5b
REPORT RequestId: 8a743c09-4f50-44d3-bbac-6e0bdfcebf5b  Duration: 111.26 ms Billed Duration: 112 ms Memory Size: 2000 MB    Max Memory Used: 91 MB  Init Duration: 382.70 ms

to
':data_final': '2025-07-09T23:59:59.999Z'

START RequestId: 845c6a5e-379d-432e-99db-340bc912bec0 Version: $LATEST
2025-07-16T15:30:25.621Z    845c6a5e-379d-432e-99db-340bc912bec0    INFO    2024-08-07T00:00:00.000Z
2025-07-16T15:30:25.622Z    845c6a5e-379d-432e-99db-340bc912bec0    INFO    2025-07-09T23:59:59.999Z
2025-07-16T15:30:25.721Z    845c6a5e-379d-432e-99db-340bc912bec0    INFO    []
END RequestId: 845c6a5e-379d-432e-99db-340bc912bec0
REPORT RequestId: 845c6a5e-379d-432e-99db-340bc912bec0  Duration: 109.04 ms Billed Duration: 110 ms Memory Size: 2000 MB    Max Memory Used: 91 MB  Init Duration: 381.52 ms

another bit of information, I have a bunch of others lines of data almost everyday from the date 2024-08-07T00:00:00.000Z to now

Edit: Also updated to add both of the results when i change the final date. On the aws console it works correctly enter image description here

8
  • 1
    Can you try the same request using the CLI or AWS console? Commented Jul 15 at 17:24
  • on the console it works correctly i'll edit the post Commented Jul 15 at 20:13
  • 1
    Can you share your entire code, that's both working and not working. Including client creation details. Commented Jul 16 at 13:13
  • 1
    I find it quite hard to believe that the query would stop working if you just change the date by one day. So I see two possibilities here: Either you also changed something else in your query/conditions or the value for data_final is not what you think it is. From your description it sounds like that data_final is some string which is, when compared as string less than data_initial. Maybe you have a typo in your value, for instance a leading whitespace or similar. Is that value hardcoded or entered by the user? Please post the exact code that is failing ... Commented Jul 16 at 13:18
  • 1
    Because you are using a filter expression, you may need to paginate your results even when only a few documents match. Check for LastEvaluatedKey in your result: (docs.aws.amazon.com/amazondynamodb/latest/developerguide/…) – the AWS js dynamodb libraries do not provide automatic pagination like those for some other languages. Commented Jul 20 at 12:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.