3

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.

1
  • Shouldn't params be like this: ``` const params = { ExpressionAttributeValues: { ":app": { S: "app" } }, IndexName: 'glc-development-gsi1', KeyConditionExpression: 'sk = :app', TableName: this.tableName, }; ``` Commented May 28, 2019 at 2:47

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.