Skip to content

documentClient with LSI returns LastEvaluatedKey for last record #3955

@jatinmehrotra

Description

@jatinmehrotra

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
I am trying pagination with LSI, my table has 3 LSI. Upon reaching the last record it should not return LastevaluatedKey, however it returns LastEvaluatedKey which makes it difficult to paginate backward.
Other 2 LSI index are working fine and keeps LastEvaluatedKey as null for last records

If on Node.js, are you running this on AWS Lambda?
yes i am running on AWS Lambda

Details of the browser/Node.js version
v16.1.0

SDK version number
v2.970.0
To Reproduce (observed behavior)

params.ScanIndexForward = false;
  response = await dynamoDb.query(paramsForQuery).promise();
  console.log('response', response);
  const arrayLength = response.Items.length;
  LastEvalSortKey = {
    pk: userId,
    originalUrl: response.Items[0].originalUrl,
  };
  if (sortBy === 'createdAt')
    LastEvalSortKey[sortBy] = response.Items[0].createdAt;
  if (sortBy === 'updatedAt')
    LastEvalSortKey[sortBy] = response.Items[0].updatedAt;
  if (sortBy === 'convertedUrl')
    LastEvalSortKey[sortBy] = response.Items[0].convertedUrl;
  return {
    items: response.Items,
    nextToken: arrayLength
      ? Base64.encodeURI(JSON.stringify(LastEvalSortKey))
      : prevToken,
    prevToken: response.LastEvaluatedKey
      ? Base64.encodeURI(JSON.stringify(response.LastEvaluatedKey))
      : undefined,
  };

Expected behavior
response.LastEvaluatedKey should be null for last record which is not, how to determine last record for reverse pagination.

Metadata

Metadata

Assignees

Labels

documentationThis is a problem with documentation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions