Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query using only partition key in DynamoDB

I am trying to query on my table using only the partition key and ignoring the sort key but I get no items.

My global secondary index looks like this: enter image description here

And my table looks like this: enter image description here

And this is my query:

const params = {
  ExpressionAttributeValues: {
    ':app': 'app',
  },
  IndexName: 'glc-development-gsi1',
  KeyConditionExpression: 'sk = :app',
  TableName: this.tableName,
};
return new Promise((resolve, reject) => {
  this.client.query(params, (err, data) => {
    console.log(data);
    if (err) {
      reject(err);
    } else {
      resolve(data);
    }
  });
});

According to all the documentation I've read and the other questions on here, this should work and I can't understand why it doesn't. The scan from my index is also empty.

like image 686
Raphael Valois Avatar asked Jul 02 '26 02:07

Raphael Valois


1 Answers

Finally found my solution. DynamoDB stores data in indexes only when both the partition key and the sort key are defined, so my index was empty all the time. The query was fine.

like image 93
Raphael Valois Avatar answered Jul 03 '26 17:07

Raphael Valois