Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
Dynamodb query with GSI and filter expression on non partition key and sort key columns in nodejs

I have a GSI on my table and am using that GSI for querying results. Am using a filter expression as well

const active_cases = await storesMonthlyAudit();
console.info("actives cases : ", active_cases)

async function storesMonthlyAudit() {
    const params = {
        TableName: "jms-case-management-dev",
        IndexName: "entity-sKey-index",
        ProjectionExpression: "storeId,caseId",
        KeyConditionExpression: "#entity = :entity",
        FilterExpression: "#status = :status",
        ExpressionAttributeNames: {
            "#entity": "entity",
            "#status": "status",
        },
        ExpressionAttributeValues: {
            ":entity": "Case",
            ":status": "Active"
        }
    };
    const cases = await Query(params);
    return cases
}

Response :

actives cases :  {
  Items: [],
  Count: 0,
  ScannedCount: 8012,
  LastEvaluatedKey: { entity: 'Case', sKey: 'C#10134066', pKey: 'ST#1013' }
}

But when I tried the same thing from AWS console, I get the correct result of 2 records with status = "Active"

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

DynamoDB will only access 1MB of data for each query request. This data access is counted before any filters or projection expressions. It appears you have more than 1 MB of data stored under your specified partition key. You need to make multiple requests to access all of the data.

The console used the LastEvaluatedKey from the response to make additional queries. You can see it consumed 559 RCUs when running your query, which means it made 5 requests in total for you to find these two values.

You likewise need to make multiple queries. You do this by setting the ExclusiveStartKey on subsequent requests, setting this value as the LastEvaluatedKey from the previous request. When LastEvaluatedKey is not returned from a request, you know that you have searched through all items that match your query.

about 4 years ago · Juan Pablo Isaza Report

0

I read about LastEvaluatedKey and ExclusiveStartKey and wrote a small function

async function dbRead(params) {
  let result = await db.query(params).promise();
  let data = result.Items;
  if (result.LastEvaluatedKey) {
    params.ExclusiveStartKey = result.LastEvaluatedKey;
    data = data.concat(await dbRead(params));
  }
  return data;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!