English 中文(简体)
Pagination bug with filtered queries - exceeding specified limit in DynamoDB
原标题:

I am encountering an issue with the paginate() function designed to handle pagination for querying DynamoDB with filters. As DynamoDB imposes certain limitations on filtered queries, I developed this function to manage pagination and ensure that the results are properly limited. However, the function is returning more results than I actually have in the database.

const docClient = new aws.DynamoDB.DocumentClient();

async paginate(params,TableName){    
  if (!params.Limit) {
    params.Limit = 10
  }

  let result = []
  let items
  let scannedItemCount = 0
  do {
    items = await docClient.scan({ TableName, ...params })
    result = result.concat(items.Items)
    if (items.Count !== null && items.Count !== undefined) {
      scannedItemCount += items.Count
    }
    params.ExclusiveStartKey = items.LastEvaluatedKey
  } while (scannedItemCount < params.Limit && items.LastEvaluatedKey)

  result.splice(params.Limit)

  return {
    items: result,
    LastEvaluatedKey: result.length > 0 ? { ...result[result.length - 1] } : undefined
  }
}

Issue: The paginate() function is not effectively limiting the results for filtered queries in DynamoDB. When executing the function with a specified params.Limit, it appears to return more results than the given limit, potentially exceeding the limitations imposed by DynamoDB on filtered queries.

Expected behavior: The paginate() function should be able to handle DynamoDB s limitations on filtered queries and correctly return results up to the specified params.Limit. If there are more results beyond the limit, they should be truncated, and the LastEvaluatedKey should be provided for subsequent pagination.

Possible fix: Given the limitations imposed by DynamoDB on filtered queries, it is essential to consider alternative approaches to handle pagination effectively. I have already attempted to address the issue by checking if items.Count is not null or undefined before incrementing the scannedItemCount, but the issue still persists.

I am seeking assistance from the community to help identify the root cause of the bug and suggest potential fixes or workarounds to ensure the paginate() function correctly limits the results for filtered queries in DynamoDB.

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签